2017-05-09 161 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

:)我們還可以用另一種方式了。 –

相關問題