nextjs13-router-events
Version:
Provides NextJS 13 router events compatible with the App Router
45 lines (37 loc) • 931 B
Markdown
Provides NextJS 13 router events compatible with the App Router
Replace regular NextJS `Link` components with this one:
```tsx
import { Link } from 'nextjs13-router-events';
```
That Link component should be compatible with your setup.
Your layout.tsx:
```tsx
import { RouteChangeProvider } from 'nextjs13-router-events';
...
return (
<RouteChangeProvider>
{children}
</RouteChangeProvider>
)
```
Your component, where you want to monitor the onRouteChangeStart and onRouteChangeComplete events:
```tsx
import { useRouteChange } from 'nextjs13-router-events';
...
export default function Component(props: any) {
...
useRouteChange({
onRouteChangeStart: () => {
console.log('onStart 3');
},
onRouteChangeComplete: () => {
console.log('onComplete 3');
}
});
...
}
```
Inspired by https://github.com/joulev/nextjs13-appdir-router-events