0

I am trying to get URL paramters in a NextJS component: http://...../page?id=1

I tried this:

export default function Page() {
    const route = useRouter()
    const params = route.params
    const id = params.get('id')

but unfortunately, 'params' is always empty. Does anyone know why or a different way of how to get the 'id' parameter

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
S34GL3
  • 3
  • 2
  • And how you got to the URI? Did you change URI with any API? – Dennis Vash Sep 28 '22 at 19:22
  • do not use params, use "query": router.query – andres martinez Sep 28 '22 at 19:23
  • Which parameters are you trying to get? There are path parameters and there are query parameters. Based on `"http://...../page?id=1"` it appears to be the latter. Use [`router.query`](https://nextjs.org/docs/api-reference/next/router#router-object). – Drew Reese Sep 28 '22 at 19:28

0 Answers0