Blazor: NavigationManager - Prevent navigation #15428
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
Milestone
I am trying to put a guard condition on navigating to a page before the navigation is attempted... i.e. before Blazor even tries to determine if the page exists.
My requirement is as follows
1: Navigation is attempted
2: My code checks if an Assembly has been loaded from the server
3: If so, then continue
4: If not, then download the assembly and then navigate to the URL requested
Other requirements could be as follows
Describe the solution you'd like
1: Change
void NavigateTo
toTask<bool> NavigateToAsync
2: Add a method
IDisposable AddNavigationGuard(Task<bool> guard, int? order = null)
The coder can call
Dispose
on the result of that to remove the guard.Before navigating, the
NavigationManager
should iterate over each guard, and await the result. If the result of any individual guard is false then the iteration should stop andNavigateToAsync
should returnfalse
.Summary
This approach would let us hook in additional logic before navigating to a page is performed.
This would allow me to create a global hook to download a DLL module before Blazor decides if the page exists or not. It would also allow developers to have in-page hooks to confirm navigation before changes are lost by using a nice async approach such as a dialog - where the registered hooks in the current page can simply be disposed of in
MyComponent.Dispose
.The text was updated successfully, but these errors were encountered: