Router query do not contain query string parameter on Router.push()
See original GitHub issueBug report
Describe the bug
I’m using the router.push method to change the page after a form submission:
const router = useRouter();
// Then later in one event handler:
router.push(
"/hotel/[websiteSeoSlug]/rooms",
/hotel/paris-nation/rooms?checkIn=2020-03-17&checkOut=2020-03-18&nbAdult=2&nbChild=2,
);
On the destination page I use again the router to extract the router query with the help of a hook:
const useFoo = (): Foo => {
const router = useRouter();
const foo = useMemo(() => {
return Foo.fromQueryString(router.query); // Sometime router.query only contain the router dynamic part and not the querystring, and some other time it contain both
}, [
...router.query
]);
return foo;
};
When I arrive on the page after a change on page on client side (router.push(…)), the router.query only contains the dynamic url part { websiteSeoSlug: "paris-nation" }.
If I refresh the page the router.query contains the dynamic url part AND the querystring parameter: { websiteSeoSlug: "paris-nation", checkIn: "2020-03-17", checkOut: "2020-03-18", nbAdult: "2", nbChild: "2" }.
Expected behavior
The router object return by useRouter should always contain the query string parameter of the current URL.
System information
- Version of Next.js: v9.3.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to hide query params from the URL while using router ...
The issue with this solution is if you refresh the page you lose the as options you've passed, making it pretty redundant for...
Read more >VueJS: $router.push not working with query parameters-Vue.js
Query parameters specified as a string do not work when passed to a path parameter: router.push({path: 'route?query=params'}).
Read more >vue router push query params - You.com | The AI Search ...
After updating vue-router from 3.4.1 to 3.4.2 a router.push() with only query params causes navigation to an empty path. Clicking the "Push query" ......
Read more >Navigate to a URL with Query Strings (Search Params) in ...
React Router has a useSearchParams hook to help us read or update the query string of a route that's active, but it doesn't...
Read more >Programmatic Navigation - Vue Router
To navigate to a different URL, use router.push . ... Note: params are ignored if a path is provided, which is not the...
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

I will close this issue as it’s a duplicate of https://github.com/zeit/next.js/issues/9473
Thanks for your help @majelbstoat
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.