diff --git a/packages/router/src/url_tree.ts b/packages/router/src/url_tree.ts index 010e7556ea..7dd79e97c9 100644 --- a/packages/router/src/url_tree.ts +++ b/packages/router/src/url_tree.ts @@ -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('//')})`; } } diff --git a/packages/router/test/create_url_tree.spec.ts b/packages/router/test/create_url_tree.spec.ts index 36cd73c789..0fc4a19232 100644 --- a/packages/router/test/create_url_tree.spec.ts +++ b/packages/router/test/create_url_tree.spec.ts @@ -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}]); diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 7ffe138188..09e9d43f7d 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -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',