next.js: withRouter query is undefined

Bug report

Describe the bug

I’m connecting a component to the router using withRouter, on the server side the router.query object is populated by the params on the URL like /post?id=1234 but on the front end, the query object is undefined for a moment and then populated again.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Clone: https://github.com/serranoarevalo/next-graph-pwa
  2. Run yarn dev
  3. Click on any of the categories
  4. See the console for a log of the router.query as undefined and then populated.

Expected behavior

The router.query should be populated with what’s on the URL

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOs
  • Browser: Chrome
  • Version of Next.js: 7.0.1

Additional context

If I refresh it works perfectly (SSR) but if I go to that page from another page the problem happens.

screen shot 2018-10-03 at 11 18 26 pm

As you can see, it’s undefined first and then it gets populated.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I’m having this same issue with pretty basic NextJS setup. The query is filled in in getInitialProps, but not in subsequent checks to this.props.router.query.

@designbyadrian @Bundas Did you find a solution? I’m also having the same issue. (Inside apollo provider, I can’t get this.props.router.query