Update query in current route
See original GitHub issueHi,
I want to programmatically update the query string in the current route, using native next router this could be done using:
// from withRouter
props.router.push({pathname: router.pathname, {query: { myParam: 'some-value' }})
This doesn’t work with next-routes because router.pathname
is ignorant of next-routes route alises.
I could make this work if we could:
- Get current URL in next-router
- Find a programmatic way to update query params in next-router
I also tried:
import routes, { Router } from './routes'
...
// router is from withRouter
const route = routes.match(router.asPath).parsedUrl
route.query.myParam = 'my-value'
Router.pushRoute(route.format())
``
But `parsedUrl` doesn't contain the query params, they are not parsed (i.e. remain in parsedUrl.search).
Any ideas?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Vue router change query on current route - Stack Overflow
When I call that method the second time, the parameters get added again. But I want it to update rather than adding another...
Read more >How to change `params/query` in current router vue? - Get Help
On some developer machines and on our dev site, using router.replace for the same route with updated params will throw a duplicate routes...
Read more >Update path query string on changes to $route.query #463
I have a pagination widget like http://materializecss.com/pagination.html in a website and when the user clicks on it to change the page, ...
Read more >Programmatically update query params in React router
Use the useSearchParams hook to programmatically update query params in React router, e.g. setSearchParams({query: 'myValue'}) . The useSearchParams hook is ...
Read more >Next.js get and update query from URL (how to guide) - Medium
2. Updating query. updateQuery becomes our useful helper function which pushes a new query to our URL via Next Router. 3. Listen for...
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 FreeTop 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
Top GitHub Comments
Is there a resolution or at least a work around to this yet?
Hi guys,
I’m experiencing the same issue, it seems there is no way to use
pushRoute
with only the query changing. I have something like/profile/:username
.I think I tried almost everything possible with
pushRoute
:I also tried with the
push
:With the
push
, it kind of works because it reload the page every time so the server side just handle it but there is not way to make it works on the client side without reloading the page. When I check thethis.props.router
query on my componentWillReceiveProps, the current props and nextProps are the same.Did you guys solved this?