You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In the SmartForm, we want to display a blocking popup "You have unsaved changes, are you sure you want to leave" on various events: closing the browser, changing route.
The problem is that "changing" route can happen at 2 levels:
in the browser. Easy to handle
in the SPA. That's where trouble begins.
The problem is that SPA route transition are handled by a router, which is framework specific. React Router was suffering from this limitation, and Next also suffers from it: you have to use a framework specific solution to block the route transitions.
Describe the solution you'd like
A pattern to tell any SPA router that we want to block route transition FIRST DRAFT OK, it triggers an event. It's app/framework responsibility to listen for those block/unblock events and add relevant behaviour for their own JS router.
For instance in React Router, that means calling history.block(), in Next, adding a listener to "beforepopstate"
eric-burel
changed the title
Listen to route changes in a SPA
Listen to route changes in a SPA without tight coupling framework specific router implementation
May 21, 2021
Is your feature request related to a problem? Please describe.
In the SmartForm, we want to display a blocking popup "You have unsaved changes, are you sure you want to leave" on various events: closing the browser, changing route.
The problem is that "changing" route can happen at 2 levels:
The problem is that SPA route transition are handled by a router, which is framework specific. React Router was suffering from this limitation, and Next also suffers from it: you have to use a framework specific solution to block the route transitions.
Describe the solution you'd like
For instance in React Router, that means calling
history.block()
, in Next, adding a listener to "beforepopstate"Demo of a generic hook: https://gist.github.com/eric-burel/75301e2ba01967e0ec909ddf7fae5100
Work ongoing there: #31
Describe alternatives you've considered
It's possible to have Next specific solution but that creates a tight coupling which we refuse
Additional context
https://github.com/ReactTraining/history/blob/master/docs/blocking-transitions.md
Added beforeRouteChangeStart vercel/next.js#5377
Browser Back Button does not trigger window.onbeforeunload vercel/next.js#2694
The text was updated successfully, but these errors were encountered: