dotnet / dotnet/aspnetcore

Blazor Router.OnNavigateAsync accept cancel or NavigationManager.ChangingHandler can handle first request

Open
#63,536 4 comments 0 reactions 0 assignees View on GitHub
area-blazor enhancement
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.

I'm using Blazor 8 Interactive Serve to complete a system.

I want redirect user to another page, if some condition meets.

- But Router.OnNavigateAsync cannot cancel previous navigation context, user sometimes see a flash.
- NavigationManager.ChangingHandler can cancel, but it cannot handle first navigation.

current workaround is a mix of
1. Set a mask flag to hide display
2. Try redirect in OnInitializedAsync, or clear flag
3. NavigationManager.ChaningHandler
4. Clear flag in OnLocationChanged

### Describe the solution you'd like

Expect a one-shot centralize solution

### Additional context

_No response_

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.