-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Support canceling of navigation #5620
Comments
It would be great if this feature will be included in the ASP.NET Core 3.0 Release. |
In Blazor Server, event handling is entirely async and browsers require that certain handlers, which includes navigation, finish synchronously. Unfortunately this is not a feature we could support. If this is absolutely necessary, we recommend using JS / JSInterop in your application to handle this. |
Then what is your recommendation to prevent the user from navigation away when they have unsaved changes on a form? This is a super common scenario. Especially in LOB applications we use Blazor primarily for. |
Maybe there could be a hidden It could support Blazor WASM navigation use-cases. |
I was able to implement a partial solution, but it's still pretty messy. This is the way it works:
This is not only a lot of custom code, but also very inefficient. If I reevaluate the state of the form at every keystroke and even push the change asynchronously to the JS side, it would burn a lot of resources. So, on top of this, I had to introduce Reactive Extensions, to Also, it handles only events initiated by the browser, so like: closing of tab (or window), refresh, navigating away to a different site. But it doesn't handle the majority of cases, when the route changes inside Blazor to another component without "unloading" the site. If anybody has a better approach, it would worth sharing, at least I would be very happy to see what is the recommended way of implementing this feature properly, which is again: pretty common in any application where you input any data. |
There is a new issue and even a pull request over at #23886 |
There is an event
OnLocationChanged
onIUriHelper
, it would be great to have support for canceling or more particularly confirming unintentional navigation.The use case is a simple form that users can change, but to don't lose any changes unintentionally, if the user tries to navigate away and the form has changed, we would like to ask him to confirm or cancel navigation.
The text was updated successfully, but these errors were encountered: