-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Blazor] Allow enhanced navigation when an interactive router is present #50012
Conversation
Opening as a draft to gather initial feedback. Still need to finish E2E tests. |
await _jsRuntime.InvokeAsync<object>(Interop.DisableNavigationInterception); | ||
} | ||
catch (JSDisconnectedException) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK for us to consume this exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. This happens if the browser is no longer available, in which case there's no browser-side state to clean up. In other words, if this exception gets thrown, it means there's no work to do.
@@ -46,6 +47,20 @@ function listenForNavigationEvents( | |||
currentHistoryIndex = history.state?._index ?? 0; | |||
} | |||
|
|||
async function enableNavigationInterception(uriInDotNet?: string) { | |||
setHasInteractiveRouter(true); | |||
if (uriInDotNet && location.href !== uriInDotNet) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what scenarios does this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example:
- The user is currently on a page with an interactive router
- The user navigates to a page without an interactive router, disposing the router and disabling navigation interception
- The user continues to click around, all while .NET is not getting notified of location changes (because no interactive router is present)
- The user navigates back to a page with an interactive router. Navigation interception gets enabled, but the itneractive router didn't get a chance to detect the navigation that just happened, so the interactive .NET
NavigationManager
still has the wrong URL and the router will therefore render content for the wrong page (or hit the "not found" route).
This sounds unintuitive to me. Wouldn't most people expect |
That's fair. But another way to think of it is that But I can definitely see that as being confusing. An alternate API I mentioned in #50014 is |
Closing in favor of #50068 |
Hi @MackinnonBuck. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Allow enhanced navigation when an interactive router is present
Adds a new API to
NavigationOptions
to prefer enhanced navigation even when an interactive router is present.Description
This PR makes the following change to
NavigationOptions
:namespace Microsoft.AspNetCore.Components; public readonly struct NavigationOptions { + public bool PreferEnhancedNavigation { get; init; } }
This property influences the behavior of
NavigationManager.NavigateTo()
:NavigationOptions.ForceLoad
istrue
ForceLoad
is true, do a full page reloadPreferEnhancedNavigation
by modifying theForceLoad
propertyFurthermore, this PR adds a new
DisableNavigationInterception
method toINavigationInterception
so that when the interactive router gets disposed, enhanced navigation can start intercepting browser-initiated navigations again.Fixes #49414