-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Allow cancellation of navigation events in Blazor #42638
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a7ae3e9
Prototype for canceling internal navigations
MackinnonBuck 05dc74b
New overlapping navigation behavior, changed APIs
MackinnonBuck c1f8602
Added APIs to block external navigations
MackinnonBuck 0af6785
Updated API baselines, added XML docs.
MackinnonBuck 298117a
Update NavigationManager.cs
MackinnonBuck 08bc4f0
Merge branch 'main' into mbuck/navigation-cancellation
MackinnonBuck f8bfc12
Safeguard for overlapping navigations
MackinnonBuck ff6b245
PR feedback
MackinnonBuck 1a7aca5
Cleanup
MackinnonBuck 7086ddd
Create blazor.webview.js
MackinnonBuck 7edfc97
Fixed deadlock, better exception handling
MackinnonBuck 055bedf
Minor cleanup
MackinnonBuck 0cea6cd
BlazorWebView support
MackinnonBuck 804b451
Started E2E tests, fixed Blazor.navigateTo() bug
MackinnonBuck 01c6484
PR feedback
MackinnonBuck ab6caad
Miscellaneous improvements
MackinnonBuck bb4d33b
Switch NavigationLock to use IDs
MackinnonBuck 6f449bb
Update RoutingTest.cs
MackinnonBuck 2fca4ce
Fixed history navigation test
MackinnonBuck 3365322
Update NavigationManagerComponent.razor
MackinnonBuck 54d7bca
PR feedback
MackinnonBuck 72230e2
Debugging test failures in CI
MackinnonBuck 4e3cca2
Updated E2E tests
MackinnonBuck 9bfc11e
Fix potential trimming issue
MackinnonBuck 7684aeb
History state entry support, more tests
MackinnonBuck 8e2b8c0
Some PR feedback
MackinnonBuck cf17ac7
PR feedback + added NavigationManager unit tests
MackinnonBuck 2771923
Updated E2E tests
MackinnonBuck 22997be
Improved exception handling, more unit tests
MackinnonBuck 8c017b8
Update TestCircuitHost.cs
MackinnonBuck 61b99ed
Improved exception handling in handler callbacks
MackinnonBuck d155810
Fixed/verified Blazor Hybrid functionality
MackinnonBuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Components/Components/src/Routing/LocationChangingContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components.Routing; | ||
|
||
/// <summary> | ||
/// Contains context for a change to the browser's current location. | ||
/// </summary> | ||
public class LocationChangingContext | ||
{ | ||
internal LocationChangingContext(string targetLocation, string? historyEntryState, bool isNavigationIntercepted, CancellationToken cancellationToken) | ||
{ | ||
TargetLocation = targetLocation; | ||
HistoryEntryState = historyEntryState; | ||
IsNavigationIntercepted = isNavigationIntercepted; | ||
CancellationToken = cancellationToken; | ||
} | ||
|
||
internal bool DidPreventNavigation { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the target location. | ||
/// </summary> | ||
public string TargetLocation { get; } | ||
|
||
/// <summary> | ||
/// Gets the state associated with the target history entry. | ||
/// </summary> | ||
public string? HistoryEntryState { get; } | ||
|
||
/// <summary> | ||
/// Gets whether this navigation was intercepted from a link. | ||
/// </summary> | ||
public bool IsNavigationIntercepted { get; } | ||
|
||
/// <summary> | ||
/// Gets a <see cref="System.Threading.CancellationToken"/> that can be used to determine if this navigation was canceled | ||
/// (for example, because the user has triggered a different navigation). | ||
/// </summary> | ||
public CancellationToken CancellationToken { get; } | ||
javiercn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// Prevents this navigation from continuing. | ||
/// </summary> | ||
public void PreventNavigation() | ||
{ | ||
DidPreventNavigation = true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.