"No router instance found." error when setting Router.beforePopState in pages/_app.js
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Router.beforePopState should be easy to set. The code should reside in pages/_app.js with client-side only guard since it should be run on client only once.
Current Behavior
I put up an example repository here.
Server-side went ok without an error, but browsers complain with the following.
No router instance found.
You should only use "next/router" inside the client side of your app.
Error: No router instance found.
You should only use "next/router" inside the client side of your app.
at throwIfNoRouter (http://localhost:3000/_next/static/commons/main.js:7835:11)
at Object.SingletonRouter.(anonymous function) [as beforePopState] (http://localhost:3000/_next/static/commons/main.js:7799:5)
at Object.<anonymous> (http://localhost:3000/_next/-/page/_app.js:2819:55)
at Object../pages/_app.js (http://localhost:3000/_next/-/page/_app.js:2955:30)
at __webpack_require__ (http://localhost:3000/_next/static/commons/manifest.js:715:31)
at fn (http://localhost:3000/_next/static/commons/manifest.js:118:20)
at Object.1 (http://localhost:3000/_next/-/page/_app.js:2962:18)
at __webpack_require__ (http://localhost:3000/_next/static/commons/manifest.js:715:31)
at webpackJsonpCallback (http://localhost:3000/_next/static/commons/manifest.js:26:23)
at http://localhost:3000/_next/-/page/_app.js:5:7
Steps to Reproduce (for bugs)
Context
See “Expected Behavior” above.
Your Environment
Tech | Version |
---|---|
next | 6.0.0 |
node | 10.0.0 |
OS | macOS High Sierra 10.13.4 |
browser | Google Chrome 66.0.3359.139 |
etc |
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Next.JS Error: No router instance found - Marcusoft.net
I have a page that is server-side rendered, since I'm the getServerSideProps . One of the components on the page, reach out and...
Read more >Next Unhandled runtime error. No router instance found
This solved the problem: Hooks error: Invalid Hook Call using NextJS or ReactJS on Windows. I was in "d/projects/.
Read more >Error: No router instance found. You should only use “next ...
Error : No router instance found. You should only use “next/router” inside the client side of your app. this error it happens when...
Read more >next/router beforePopState not firing : r/nextjs - Reddit
As per title, beforePopState just doesn't fire when I hit the back button. This code is a hook called in _app.js as per...
Read more >next/router | Next.js
Learn more about the API of the Next.js Router, and access the router instance in your page with the useRouter hook.
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
@peacefullybound Well at first i did have the same problem as yours, and after move that code to componentDidMount in
_app.js
the error disappear, but unfortunately it’s still not working as well without any error informed on the dev console, here is my componentDidUpdate code:my next version is 6.0.3, please share how you solved this issue
hi @peacefullybound i did move it to componentDidMount lifecycle but unfortunately it still didnt work whenever i changed the route, any thought tho?