Relative Content

Tag Archive for next.jsevent-listenernext-routerremoveeventlistener

Prevent routing to another page except when the form page is submitted

I have a custom context UserRegistrationContextProvider that saves the form data and submit it, and my page is a form that I want to detect before the user change the route to prevent it and show a popup asking to confirm navigation or cancel, I made a custom use hook (useLeavePageConfirm) to handle this logic. The problem I am facing is when the user submit the form, I want to navigate to other page and this trigger the event so the popup appear and I don’t want it to appear nor to prevent the routing in this case.