
We use a Custom App ( pages/_app.js) for this example to subscribe to the event because it's not unmounted on page navigations, but you can subscribe to router events on any component in your application.


If you want to access the router object inside any function component in your app, you can use the useRouter hook, take a look at the following example: import

Before moving forward, we recommend you to read Routing Introduction first.
