如何从Next.js中的URL获取(查询字符串)参数? [英] How to get (query string) parameters from URL in Next.js?
本文介绍了如何从Next.js中的URL获取(查询字符串)参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击我的/index.js
中的链接时,它带我到/about.js
页面.
但是,当我通过URL(例如/about?name = leangchhean )将参数名称从/index.js
传递到/about.js
时,我不知道如何在/about.js
页面中获取它
When I click on a link in my /index.js
, it brings me to /about.js
page.
However, when I'm passing parameter name through URL(like /about?name=leangchhean) from /index.js
to /about.js
, I don't know how to get it in /about.js
page.
index.js
import Link from 'next/link'
export default () => (
<div>Click <Link href={{ pathname: 'about', query: { name: 'leangchhean' }}}><a>here</a></Link> to read more</div>
)
推荐答案
-
使用about.js页面中的以下代码来获取它:
Get it by using below code in the about.js page:
// pages/about.js import Link from 'next/link' export default ({ url: { query: { name } } }) => ( <p>Welcome to About! { name }</p> )
这篇关于如何从Next.js中的URL获取(查询字符串)参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文