0

I have a string which look like this /dashboard/products/:id and I want to use Next Js's router to push into that url and change the :id into a valid id.

This is my code

{products.map(product => <ProductCard onClick={() => router.push(PATHS.productDetail, { query: { id: 1 } })} />)}

My expectation is the user would be redirected to /dashboard/products/1 but it goes to /dashboard/products?id=1

Is there any workaround for this problem? Thanks

1 Answer 1

2

You should use that pattern for the URL

  router.push({
    pathname: '/dashboard/products/[id]',
    query: { id: 2 },
  })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.