Skip to content

Conversation

@atscott
Copy link
Contributor

@atscott atscott commented Dec 22, 2025

This updates the state manager to allow intercepting and deferring commits of traversal navigations.
The issues that were encountered in the past appear to be resolved in Chrome.
The behavior of redirect is still undefined in this case, so there is an added TODO.

Reviewer not: First 3 commits are in other (approved) PRs. Only the last commit is needing review

…supported

This commit adds a token that indicates whether the precommitHandler feature
is supported by the navigation api.

https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/intercept#precommithandler
…gration

The `precommitHandler` of the Navigation API unlocks some of the truly
powerful features for Routers like Angular's which defer the URL
updates. Without the `precommitHandler`, we cannot initiate a navigation
until we are ready to commit the URL because it causes the URL to update
immediately.

With `precommitHandler` support, we are able to create a `NavigateEvent`
_immediately_ on navigation, which allows the browser to show that a
navigation is happening with a loading indicator. Site visitors will
also have the ability to cancel the navigation with the "stop" button.
When we are ready to commit the URL, the precommitHandler supports a
"redirect" function that we can use to first redirect the navigation to
a new location immediately before committing it.

The commit operation is not synchronous because the API waits for all
precommitHandlers to resolve. This commit adds a small bit of handling
to account for this so that the Router's transition does not advance
to the next stage until the URL has been committed.
This builds off of angular#66197 by retaining the original navigateEvent across redirects
so the NavigateEvent can more accurately track the lifecycle of a navigation,
which may span across several NavigationStart events due to redirects
@angular-robot angular-robot bot added area: common Issues related to APIs in the @angular/common package area: router labels Dec 22, 2025
@ngbot ngbot bot added this to the Backlog milestone Dec 22, 2025
@atscott atscott marked this pull request as draft December 23, 2025 19:53
This updates the state manager to allow intercepting and deferring commits of traversal navigations.
The issues that were encountered in the past appear to be resolved in Chrome.
The behavior of redirect is still undefined in this case, so there is an added TODO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common Issues related to APIs in the @angular/common package area: router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant