Live Chat Icon For mobile
Live Chat Icon

How do you detect navigation events in Blazor WebAssembly?

Platform: Blazor| Category : General, Event handling

LocationChangedis an event handler that will fire when the navigation location has been changed. The following example uses a JavaScript interop function to alert the user when the navigation location changes.

@inject NavigationManager UriHelper
@inject IJSRuntime JSRuntime

@code {
    protected override void OnInitialized()
    {
        UriHelper.LocationChanged += DetectNavigation;
    }

    private void DetectNavigation(object sender, LocationChangedEventArgs e)
    {
        JSRuntime.InvokeVoidAsync("alert", "Navigation event triggered");
    }
}

Refer to this documentation for more details.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.