Next.js Discord

Discord Forum

Detect route change

Unanswered
Havana posted this in #help-forum
Open in Discord
HavanaOP
How to detect route change in NextJS 13?

2 Replies

what do you want to do on route change... if you are on app dir, you could use [usePathname](https://nextjs.org/docs/app/api-reference/functions/use-pathname), and the hook will change on pathname change on client
HavanaOP
@riský
I would like to create a CanDeactivate-Guard feature that monitors for any modifications on a page, such as changes to form values. In the event that a user attempts to navigate away from the page, perhaps by clicking on a different menu item, a popup notification will be triggered. This notification will inquire whether the user genuinely intends to exit the page at that moment.