[Blazor] Allow enhanced navigation when an interactive router is present#50012
[Blazor] Allow enhanced navigation when an interactive router is present#50012MackinnonBuck wants to merge 1 commit intomainfrom
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.
Is it OK for us to consume this exception?
There was a problem hiding this comment.
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.
|
|
||
| async function enableNavigationInterception(uriInDotNet?: string) { | ||
| setHasInteractiveRouter(true); | ||
| if (uriInDotNet && location.href !== uriInDotNet) { |
There was a problem hiding this comment.
In what scenarios does this happen?
There was a problem hiding this comment.
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
NavigationManagerstill 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
NavigationOptionsto 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.ForceLoadistrueForceLoadis true, do a full page reloadPreferEnhancedNavigationby modifying theForceLoadpropertyFurthermore, this PR adds a new
DisableNavigationInterceptionmethod toINavigationInterceptionso that when the interactive router gets disposed, enhanced navigation can start intercepting browser-initiated navigations again.Fixes #49414