Skip to content

fix(router): reset internal state on error handler redirect after state commit - #71130

Merged
kirjs merged 1 commit into
angular:mainfrom
atscott:fix-redirect-after-commit
Oct 2, 2026
Merged

kirjs merged 1 commit into
angular:mainfrom
atscott:fix-redirect-after-commit

Conversation

@atscott

@atscott atscott commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

When an error occurs after BeforeActivateRoutes has already committed targetRouterState and withNavigationErrorHandler returns a RedirectCommand, the transition emits a redirecting NavigationCancel instead of NavigationError. Previously, StateManager skipped resetting internal state on all redirecting cancellations because redirects from guards and resolvers happen prior to BeforeActivateRoutes. This left the half-activated targetRouterState (whose unactivated routes do not yet have snapshot assigned) as the current routerState for the subsequent redirect navigation.

This change resets internal state if a redirecting cancellation occurs after targetRouterState was already committed.

Fixes #71126

@ngbot ngbot Bot added this to the Backlog milestone Oct 1, 2026
@atscott
atscott force-pushed the fix-redirect-after-commit branch from e8cc871 to 5009842 Compare October 1, 2026 19:44
@atscott
atscott force-pushed the fix-redirect-after-commit branch from 5009842 to 2c0694f Compare October 1, 2026 19:51
@atscott atscott added the target: patch This PR is targeted for the next patch release label Oct 1, 2026
@atscott
atscott force-pushed the fix-redirect-after-commit branch from 2c0694f to edd00af Compare October 1, 2026 19:55
…te commit

When an error occurs after `BeforeActivateRoutes` has already committed
`targetRouterState` and `withNavigationErrorHandler` returns a
`RedirectCommand`, the transition emits a redirecting `NavigationCancel`
instead of `NavigationError`. Previously, `StateManager` skipped resetting
internal state on all redirecting cancellations because redirects from guards
and resolvers happen prior to `BeforeActivateRoutes`. This left the uncommitted
or half-activated `targetRouterState` (whose unactivated routes do not yet have
`snapshot` assigned) as the current `routerState` for the subsequent redirect
navigation.

This change resets internal state if a redirecting cancellation occurs after
`targetRouterState` was already committed.

Fixes angular#71126
@atscott
atscott force-pushed the fix-redirect-after-commit branch from edd00af to 654828d Compare October 1, 2026 20:12
@atscott
atscott requested a review from alan-agius4 October 1, 2026 20:15

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Oct 2, 2026
@atscott

atscott commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@kirjs
kirjs merged commit f591d36 into angular:main Oct 2, 2026
25 checks passed
@kirjs

kirjs commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: router target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular Router state committed before activation can make a valid error-handler redirect loop forever

3 participants