fix(router): Fix relative link generation from empty path components (#37446)

Partial resubmit of #26243
Fixes incorrect url tree generation for empty path components with children.
Adds a test to demonstrate the failure of createUrlTree for those routes.
Fixes #13011
Fixes #35687

PR Close #37446
This commit is contained in:
Andrew Scott
2020-06-08 09:26:16 -07:00
committed by atscott
parent 946f1179e9
commit 8d817daf78
2 changed files with 32 additions and 4 deletions

View File

@ -148,7 +148,12 @@ function findStartingPosition(nav: Navigation, tree: UrlTree, route: ActivatedRo
}
if (route.snapshot._lastPathIndex === -1) {
return new Position(route.snapshot._urlSegment, true, 0);
const segmentGroup = route.snapshot._urlSegment;
// Pathless ActivatedRoute has _lastPathIndex === -1 but should not process children
// see issue #26224, #13011, #35687
// However, if the ActivatedRoute is the root we should process children like above.
const processChildren = segmentGroup === tree.root;
return new Position(segmentGroup, processChildren, 0);
}
const modifier = isMatrixParams(nav.commands[0]) ? 0 : 1;