Closed mrpmorris closed 5 years ago
I think this is related to #14962
I have cross-cutting use-cases for this, too: parent components with state that navigation-producing child components are unaware of. I was a little surprised there isn't a general Cancel
method on the System.EventArgs
base class.
I've added a pull request, but cancelling it because it's not the way it should be done. I will update the issue to explain why.
Duplicate of #14962
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 methodIDisposable 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
.