-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
beforeunload for post-pushState/replaceState navigations #2961
Comments
Related to #2710 |
Can you give an example of "many routers" and "some cases"? Unlike history.index, this is not something I have seen a lot. |
react-redux-router |
See remix-run/history#690 for why the current situation does not work. |
Duplicate this into #5562? |
@annevk - that one seems to be about monitoring navigations, not about preventing them and re-applying them. |
Chromium is interested in solving this use case, as part of a larger overhaul of the history API to make it more suitable for single-page applications. Take a look, and feel free to comment with support, in WICG/proposals#20. In particular, the navigation monitoring and interception section touches on this. |
@domenic - hmmm, from the complete explainer -
Not sure how this solves this specific ("beforeunload for post-pushState/replaceState navigations") issue. |
Ah, OK, then yeah, there's no interest in letting developers intercept browser back buttons or URL bar navigations; that'd be too open to abuse. |
@domenic - so it is fine (I know it is not) for cross origin/non-single-page navigations but not for single page? A bit of a stretch. It is like encouraging non-single-page for not losing data, which sounds backwards. But I understand where you are coming from. Not agreeing, but understanding. |
By the way, preventing a locking in a user in a domain is a user interface issue and not a functional issue - the browser can show single-page entries and the last non-single-page (or even the last cross-origin) entry, making it easy for the user to get out of the site. |
Many routers have the ability to stop a navigation, either by using the
beforeunload
event, or by re-pushing a navigation to the history.The former works only when navigating would reload/load the top level frame.
The latter breaks back/forward in some cases.
Perhaps there should be a cancellable
beforepopstate
event that would prevent navigation from happening. Another feature could be a promise attribute (or maybeevent.waitUntil
) on the event object that would commit the navigation when resolved (say, the user decided to indeed leave the page).The text was updated successfully, but these errors were encountered: