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