dotnet / dotnet/aspnetcore

Implement NavigationManager.NavigateToAsync

Open
#64,813 4 comments 2 reactions 0 assignees View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

A client I am working for has a LayoutComponent that has various data functions such as CRUD + Search. Upon selecting an object to edit it uses NavigationManager to navigate.

Once the child content has updated, the layout needs to update its state. However, we cannot wait until the navigation is complete because NavigateTo is synchronous.

The navigation process might take a long time due to a modal "Do you want to cancel your changes" confirmation that is hooked into NavigationManager.RegisterLocationChangingHandler.

### Describe the solution you'd like

# Request 1
I wrote something myself, but it isn't ideal. My biggest problem is not being able to know if the navigation has been cancelled so that I can cancel the task immediately. Could we have a "Task NavigationCancelled" property on LocationChangingContext?

# Request 2
Add NavigateToAsync overloads to NavigationManager.

I'm not sure at which point the task should be marked as completed

1. After all LocationChangingHandlers have approved?
2. After LocationChanged event has fired?
3. After LocationChanged event + the page SetParametersAsync has first completed?
4. Something else?

Option 2 might be best?

### Additional context

Not sure how this would work with a page's IDisposable.Dispose being called whilst it navigates asynchronously to another page and awaits the result.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.