-
Notifications
You must be signed in to change notification settings - Fork 39
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
Prompt for unsaved forms #45
Comments
Closes mefechoel#45
Closes mefechoel#45
history.pushState = new Proxy(history.pushState, {
apply (target, thisArg, argumentsList) {
// Code here will execute *before* the navigation (and may prevent it by return-ing early)
// ... code ...
Reflect.apply(target, thisArg, argumentsList);
// Code here will execute *after* the navigation
// ... code ...
}
}) I still would appreciate official support for this! |
I'm hesitant to add this to the library (for now) as it would require quite a bit of modification to the history module, as well as some new components (a Prompt component probably). Yout described solution using a proxy will work, but only on pushstate calls, which is only half the story. Browser back and forth buttons won't be intercepted here. |
i think it will be very helpful in this case if you can provide any way to replace the global history, including the default |
Thank you for this library!
I'm looking for something like React routers Prompt.
When there is unsaved work there are three ways the user should be warned:
window.onbeforeunload
: The user presses refresh in the browser or navigates to another websitenavigate
: The user presses on an internal link that will change the page in the routerpopstate
: The user presses back in the browser1 and 2 are solvable relatively easily.
createHistory
could allow registering callbacks for handling prompts. If any of these listeners return an unsuccessful value (as in there is unsaved work) a prompt would be displayed.3 is a bit more tricky since the browser doesn't offer a way to block the URL change. Thus on cancel we'd have to navigate back to the page the user just left. This would have to be done before the router removes anything from the page so that no state is lost. This is what react-router does, I think.
Has any work in this area been done? I'll create an implementation if you don't see anything wrong with this approach.
The text was updated successfully, but these errors were encountered: