fix(router): remove parenthesis for primary outlet segment after removing auxiliary outlet segment (#24656) (#37163)

For URLs that use auxiliary route outlets in the second or following path segments,
when removing the auxiliary route segment, parenthesis remain for the primary outlet segment.
This causes the following error when trying to reload an URL: "Cannot match any route".
The commit adds a check for this scenario, serializing the URL as "a/b" instead of "a/(b)".

PR Close #24656

PR Close #37163
This commit is contained in:
ggradnig 2020-05-17 15:16:08 +02:00 committed by Misko Hevery
parent 1197965e69
commit 71f008f906
3 changed files with 12 additions and 1 deletions

View File

@ -341,6 +341,11 @@ function serializeSegment(segment: UrlSegmentGroup, root: boolean): string {
return [`${k}:${serializeSegment(v, false)}`];
});
// use no parenthesis if the only child is a primary outlet route
if (Object.keys(segment.children).length === 1 && segment.children[PRIMARY_OUTLET] != null) {
return `${serializePaths(segment)}/${children[0]}`;
}
return `${serializePaths(segment)}/(${children.join('//')})`;
}
}

View File

@ -128,6 +128,12 @@ describe('createUrlTree', () => {
expect(serializer.serialize(t)).toEqual('/a');
});
it('should support removing parenthesis for primary segment on second path element', () => {
const p = serializer.parse('/a/(b//right:c)');
const t = createRoot(p, ['a', {outlets: {right: null}}]);
expect(serializer.serialize(t)).toEqual('/a/b');
});
it('should update matrix parameters', () => {
const p = serializer.parse('/a;pp=11');
const t = createRoot(p, ['/a', {pp: 22, dd: 33}]);

View File

@ -3351,7 +3351,7 @@ describe('Integration', () => {
advance(fixture);
expect(log.map((a: any) => a.path)).toEqual(['b']);
expect(location.path()).toEqual('/two-outlets/(a)');
expect(location.path()).toEqual('/two-outlets/a');
})));
it('works with a nested route',