What is the NavigationLock component, and how do you use it to prevent a user from leaving a dirty form?

Last updated 5 July 2026

  • NavigationLock (.NET 7+) is a component that declaratively intercepts navigation away from the current page.

  • Bind ConfirmExternalNavigation to an isDirty flag to show the browser's native "leave site?" dialog on URL changes and page unloads.

  • Handle OnBeforeInternalNavigation for in-app links: prompt the user and call context.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
All Blazor interview questions