Skip to content

Commit

Permalink
docs: Fix imports in router API reference (#9977)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzKn authored and Timer committed Jan 7, 2020
1 parent c6e6d98 commit f44f9e2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/api-reference/next/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ You can listen to different events happening inside the Router. Here's a list of
For example, to listen to the router event `routeChangeStart`, do the following:

```jsx
import Router from 'router/events'
import Router from 'next/router'

const handleRouteChange = url => {
console.log('App is changing to: ', url)
Expand All @@ -221,15 +221,15 @@ Router.events.on('routeChangeStart', handleRouteChange)
If you no longer want to listen to the event, unsubscribe with the `off` method:

```jsx
import Router from 'router/events'
import Router from 'next/router'

Router.events.off('routeChangeStart', handleRouteChange)
```

If a route load is cancelled (for example, by clicking two links rapidly in succession), `routeChangeError` will fire. And the passed `err` will contain a `cancelled` property set to `true`, as in the following example:

```jsx
import Router from 'router/events'
import Router from 'next/router'

Router.events.on('routeChangeError', (err, url) => {
if (err.cancelled) {
Expand All @@ -241,7 +241,7 @@ Router.events.on('routeChangeError', (err, url) => {
Router events should be registered when a component mounts ([useEffect](https://reactjs.org/docs/hooks-effect.html) or [componentDidMount](https://reactjs.org/docs/react-component.html#componentdidmount) / [componentWillUnmount](https://reactjs.org/docs/react-component.html#componentwillunmount)) or imperatively when an event happens, as in the following example:

```jsx
import Router from 'router/events'
import Router from 'next/router'

useEffect(() => {
const handleRouteChange = url => {
Expand Down

0 comments on commit f44f9e2

Please sign in to comment.