Router push with URL object doesn't replace path parameter by the query property value
See original GitHub issueBug report
Description
The router doesn’t be replacing the first parameter from the pathname
by the property value defined in query
object
Example
If I have the following pages directory tree /pages/posts/[postId]/edit
and use router push with the following parameters
{
pathname: '/posts/[postId]/edit',
query: { postId: 1 }
}
It’s ok, the router sends to the browser the following path /posts/1/edit
But, if I have a pages directory tree like /pages/posts/[postId]/comments/[commentId]
and use router push with the following parameters
{
pathname: '/posts/[postId]/comments/5',
query: { postId: 1 }
}
The router sends to the browser the following path /posts/[postId]/comments/5?postId=1
. The router doesn’t replace the parameter postId
by the query property value.
My Next.js version is 10.0.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
$router.push({query: this.myarray}) not updating the URL · ...
replace ({ query: {} }) ! Replacing to existing name or path works, query doesn't. What am I doing wrong, guys? I want...
Read more >How to use router.push for same path, different query ...
That's because it's not different from your current path. If the value of type is different it won't give you NavigationDuplicated error.
Read more >Routing in Vue3: Navigating the Options
To start out, you'll need to create an array of objects that describe each route. A route typically has a name, a path,...
Read more >Location
A service that applications can use to interact with a browser's URL. ... unknown : The current value of the history.state object. ......
Read more >Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@souzantero happy to help, I’m gonna close this since it seems to be resolved.
Hi, @ijjk . I get this error whenever I use href directly without interpolation. According to the examples in the link you sent above, it’s supposed to work, but this error ensues every time:
I’m passing href directly like so…
…and then it throws the unhandled runtime error above.
Kindly, what am I doing wrong here? And how do I fix?
Thanks for your swift response.