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

3
  • And how you got to the URI? Did you change URI with any API? Commented Sep 28, 2022 at 19:22
  • do not use params, use "query": router.query Commented Sep 28, 2022 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. Commented Sep 28, 2022 at 19:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.