What is the NavigationLock component, and how do you use it to prevent a user from leaving a dirty form?
Last updated
NavigationLock(.NET 7+) is a component that declaratively intercepts navigation away from the current page.Bind
ConfirmExternalNavigationto anisDirtyflag to show the browser's native "leave site?" dialog on URL changes and page unloads.Handle
OnBeforeInternalNavigationfor in-app links: prompt the user and callcontext.PreventNavigation()if they cancel.
- https://github.com/dotnet/aspnetcore/issues/42877
- https://medium.com/@@mariekie/blazor-features-in-net-7-c6ddf6de0107
- https://www.telerik.com/blogs/blazor-new-locationchanging-events-dotnet-7
- https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/navigation?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/answers/questions/1302932/can-i-have-navigationlock-apply-to-the-parent-comp