I have a Blazor Web App solution that utilizes the Navigation Manager to manage navigation. I want to prevent navigation on a test page I made if the user makes any input in a text box. Render modes are set on a per component/per page basis. Currently, in Web.Server I have a MainLayout.razor that displays a nav bar displaying on the side of the page I am on. The nav bar comes from SideNav.razor, and on this file I include @rendermode InteractiveServer.
In Web.Client I have a TestPage.razor with @rendermode InteractiveWebAssembly that includes an input box and utilizes a location changing handler:
protected override void OnAfterRender(bool firstRender){ if (firstRender) { registration = Navigation.RegisterLocationChangingHandler(OnLocationChanging); }}private ValueTask OnLocationChanging(LocationChangingContext context){ if (inputHasChanged) { // Other code context.PreventNavigation(); } return ValueTask.CompletedTask;}Currently, if I include a link using NavigateTo on the page, it triggers the event handler and I can prevent navigation. If I include a link using NavigateTo on the nav bar, it does not trigger the event handler and immediately navigates away. I also wanted to add, an a tag with an href (for example, <a href="/">Home</a>) also does not trigger the event handler.
Navigation Manager is injected into all of the files, so I am not sure what is going on. Could someone help me with this?