fix(router): pass correct component to canDeactivate for named outlets in componentless parent routes#69591
Open
arturovt wants to merge 1 commit into
Open
fix(router): pass correct component to canDeactivate for named outlets in componentless parent routes#69591arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a componentless parent route has children rendered into a named outlet (e.g.
outlet: 'inner'), thecanDeactivateguard receivednullas the component argument instead of the actual component instance.The bug was in
deactivateRouteAndItsChildren: for componentless routes, each child was passed the samecontextinherited from the parent lookup, which wasnullwhen the parent component only registered a named outlet. The children's actual outlet contexts were never consulted.The fix adds a
parentContexts: ChildrenOutletContexts | nullparameter so that for componentless routes, each child is looked up by its own outlet name inparentContexts(e.g.parentContexts.getContext('inner')). For component routes,context.childrenis passed as the newparentContextson recursion, ensuring correct context resolution across component boundaries.This re-addresses #34614. A previous fix (#36302) was reverted because it passed
parentContextsunchanged through component boundaries; this fix updatesparentContextstocontext.childrenwhen descending into a component route, preventing the wrong contexts from propagating into deeper componentless levels.Fixes #34614