Last post May 24, 2020 01:18 AM by BlazorFan
May 17, 2020 08:58 AM|Zero-G.|LINK
Is there a way to get the NavigationManager somewhere centralized in code?
I want to log each Navigation change (NavigationManager.NavigateTo("/index"). I don't want to write a log order to each navigation command.
THX a lot in advance
May 24, 2020 01:18 AM|BlazorFan|LINK
Since in Blazor a user never disconnects until they leave, if you inject a class in the startup file and create an instance of it when the user first starts, then it is always there until the user leaves the site.
In this class sign up for the NavigationManager.LocationChanged event.
It should run quietly in the background, logging the changing url.
Dispose of it when the user exits the application so you don't get a memory leak.