dotnet / dotnet/aspnetcore

Trigger LocationChanging callbacks on enhanced navigation

Open
#48,766 1 comment 0 reactions 0 assignees View on GitHub
area-blazor enhancement feature-blazor-navigation feature-full-stack-web-ui Pillar: Complete Blazor Web Priority:1
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Location changing handlers may not always be invoked on enhanced navigation. For example, when no interactive router is present, interactive components cannot intercept user-initiated navigations.

From @MackinnonBuck:

> "When an enhanced navigation occurs, `LocationChanged` event handlers registered in interactive runtimes (i.e., Blazor Server/WebAssembly) get invoked. However, location changing handlers may or may not intercept enhanced navigations, so it's important that app logic not rely on location changing handlers being invoked reliably. For example, the user might switch to another page before an interactive runtime becomes available. In .NET 8, if server-side routing and enhanced navigation are enabled, location changing handlers will only get invoked for programmatic navigations initiated from an interactive runtime. In future .NET versions, more types of navigations (e.g., link clicks) may also invoke location changing handlers".

A more detailed analysis of when location changing handlers get invoked can be found [here](https://github.com/dotnet/aspnetcore/issues/51436#issuecomment-1769323645).

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.