I'm working on MAUI app and want to execute some code every time when I change url. How to implement it?
CodePudding user response:
In your App.razor
, Add these lines of code:
@inject NavigationManager NavigationManager
@implements IDisposable
@code {
protected override void OnInitialized() => NavigationManager.LocationChanged = OnLocationChanged;
private void OnLocationChanged(object? sender, EventArgs e)
{
//your code
Console.WriteLine("Location Changed...");
}
public void Dispose() => NavigationManager.LocationChanged -= OnLocationChanged;
}