Skip to content

fix(router): pass correct component to canDeactivate for named outlets in componentless parent routes#69591

Open
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/router_34614
Open

fix(router): pass correct component to canDeactivate for named outlets in componentless parent routes#69591
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/router_34614

Conversation

@arturovt

Copy link
Copy Markdown
Contributor

When a componentless parent route has children rendered into a named outlet (e.g. outlet: 'inner'), the canDeactivate guard received null as the component argument instead of the actual component instance.

The bug was in deactivateRouteAndItsChildren: for componentless routes, each child was passed the same context inherited from the parent lookup, which was null when the parent component only registered a named outlet. The children's actual outlet contexts were never consulted.

The fix adds a parentContexts: ChildrenOutletContexts | null parameter so that for componentless routes, each child is looked up by its own outlet name in parentContexts (e.g. parentContexts.getContext('inner')). For component routes, context.children is passed as the new parentContexts on recursion, ensuring correct context resolution across component boundaries.

This re-addresses #34614. A previous fix (#36302) was reverted because it passed parentContexts unchanged through component boundaries; this fix updates parentContexts to context.children when descending into a component route, preventing the wrong contexts from propagating into deeper componentless levels.

Fixes #34614

…s in componentless parent routes

When a componentless parent route has children rendered into a named outlet
(e.g. `outlet: 'inner'`), the `canDeactivate` guard received `null` as the
component argument instead of the actual component instance.

The bug was in `deactivateRouteAndItsChildren`: for componentless routes,
each child was passed the same `context` inherited from the parent lookup,
which was `null` when the parent component only registered a named outlet.
The children's actual outlet contexts were never consulted.

The fix adds a `parentContexts: ChildrenOutletContexts | null` parameter so
that for componentless routes, each child is looked up by its own outlet name
in `parentContexts` (e.g. `parentContexts.getContext('inner')`). For
component routes, `context.children` is passed as the new `parentContexts`
on recursion, ensuring correct context resolution across component boundaries.

This re-addresses angular#34614. A previous fix (angular#36302) was reverted because it
passed `parentContexts` unchanged through component boundaries; this fix
updates `parentContexts` to `context.children` when descending into a
component route, preventing the wrong contexts from propagating into deeper
componentless levels.

Fixes angular#34614
@pullapprove pullapprove Bot requested a review from atscott June 30, 2026 18:25
@ngbot ngbot Bot added this to the Backlog milestone Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incorrect component passed to canDeactivate guard

1 participant