Router query empty in componentDidMount
See original GitHub issueBug report
Describe the bug
The docs state: The query object will be empty during prerendering if the page is statically optimized.
but I am also seeing the query object empty in the componentDidMount
lifecycle method.
To Reproduce
- Clone https://github.com/zlwaterfield/next-router-query-test
- Run
yarn dev
- Go to http://localhost:3004/router-test?test=test
- Notice the query object is empty but the
document.location.search
is correct and the query shows inasPath
.
Expected behavior
The query object should be
{
test: 'test'
}
Screenshots
System information
- Version of Next.js:
9.4.0
Additional context
I understand the query object would be empty in the prerender but should it not show when the component is mounted?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (5 by maintainers)
Top Results From Across the Web
useRouter/withRouter receive undefined on query in first render
During prerendering stage of the component, the query object of the router will be empty. isReady: boolean - Whether the router fields are ......
Read more >next/router | Next.js
query : Object - The query string parsed to an object, including dynamic route parameters. It will be an empty object during prerendering...
Read more >Fixing Next.js router query param returning undefined on ...
First, let's just try to reproduce this issue. You might encounter some cases where you need access to query params of a route....
Read more >How to Search and Filter Components in React - freeCodeCamp
How to Build the Search Component. Inside our APP function we use the useState() hooks to set the query q to an empty...
Read more >Using Suspense and React Query: Tutorial with examples
If you need to fetch data from a source, for example, an API, you usually need to create a request in the useEffect()...
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
Ah, I found this:
I will confirm this and then look into making a PR to make it more clear in the docs. Thanks for the help.
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.