Skip to content

Commit

Permalink
expanded on No Router Instance (#21248)
Browse files Browse the repository at this point in the history
Added more detailed explanation of why there is no router instance, and other ways to fix the error
  • Loading branch information
Robogeek95 committed Jan 26, 2021
1 parent c110e45 commit 00d453d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions errors/no-router-instance.md
Expand Up @@ -2,8 +2,12 @@

#### Why This Error Occurred

During SSR you might have tried to access a router method `push`, `replace`, `back`, which is not supported.
During Pre-rendering (SSR or SSG) you tried to access a router method `push`, `replace`, `back`, which is not supported.

#### Possible Ways to Fix It

Move any calls to router methods to `componentDidMount` or add a check such as `typeof window !== 'undefined'` before calling the methods
In a function Component you can move the code into the `useEffect` hook.

In a class Component, move any calls to router methods to the `componentDidMount` lifecycle method.

This way the calls to the router methods are only executed in the browser.

0 comments on commit 00d453d

Please sign in to comment.