next/navigation: replace path parameter #65767
Unanswered
jamesarosen
asked this question in
Help
Replies: 2 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
4 replies
-
Have you managed to find a workaround for this? almost a year later and I have almost the same problem, and cant see a better solution than just use router.push(`route/${param}`) would be nice to have a way to get the current pathname without the dynamic route segments |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I'm trying to build a component that lets the user switch a path parameter. I can do this using the older
next/router
, but I'm unable to figure out how to do this withnext/navigation
.Some constraints:
For example, given these routes
if the user is on
/books/12/comments?sort=popular
and uses the component to change thebook_id
to46
, they go to/books/46/comments?sort=popular
Here's how I might implement that in the older
next/router
:If the
book_id
were in theURLSearchParams
, this would be easy to convert to next/navigation'suseSearchParams
anduseRouter
. But as far as I can tell, next/navigation doesn't offer a way to change path params.Is the "correct" solution to have each of these pages know how to swap the path parameter while leaving the search params intact?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions