-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow cancellation of navigation events in Blazor (#42638)
- Loading branch information
1 parent
6ad8ac4
commit de68fea
Showing
36 changed files
with
2,280 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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; } | ||
|
||
/// <summary> | ||
/// Prevents this navigation from continuing. | ||
/// </summary> | ||
public void PreventNavigation() | ||
{ | ||
DidPreventNavigation = true; | ||
} | ||
} |
Oops, something went wrong.