2017-05-09 143 views
2

当我点击index.js中的链接时,它会将我带到about.js页面。 当我通过从index.js到about.js的url传递参数名称时,我不知道如何在about.js页面中获取它。nextjs:如何从Next.js中的url获取GET(查询字符串)参数?

我的代码在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> 
) 

网址:http://localhost:3000/about?name=leangchhean

回答

2
  • 由about.js页使用下面的代码获取它:

    enter image description here

// pages/about.js 
 
import Link from 'next/link' 
 
export default ({ url: { query: { name } } }) => (
 
    <p>Welcome to About! { name }</p> 
 
)

+1

:)我们还可以用另一种方式了。 –

相关问题