How can I get (query string) parameters from the URL in Next.js?

后端 未结 8 523
情深已故
情深已故 2020-12-13 01:32

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

相关标签:
8条回答
  • 2020-12-13 02:28

    If you need to retrieve a URL query from outside a component:

    import router from 'next/router'
    
    console.log(router.query)
    
    
    0 讨论(0)
  • 2020-12-13 02:31
    • Get it by using the 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>
    )

    0 讨论(0)
提交回复
热议问题