question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router query do not contain query string parameter on Router.push()

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
armandabriccommented, Mar 19, 2020

I will close this issue as it’s a duplicate of https://github.com/zeit/next.js/issues/9473

Thanks for your help @majelbstoat

0reactions
balazsorban44commented, Jan 30, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found