The LocationChanged event handler is triggered when there is a change in the navigation location. In the example below, a JavaScript interop function is used to display an alert to the user whenever the navigation location changes:
@inject NavigationManager UriHelper
@inject IJSRuntime JSRuntime
<p> When navigating to another page, an alert box will be displayed to indicate the navigation. </p>
@code {
protected override void OnInitialized ()
{
UriHelper.LocationChanged += DetectNavigation;
}
private void DetectNavigation ( object sender, LocationChangedEventArgs e )
{
JSRuntime.InvokeVoidAsync("alert", "Navigation event is triggered");
}
}
Refer to this documentation for more details.
Share with