diff --git a/packages/router/src/create_url_tree.ts b/packages/router/src/create_url_tree.ts index 2a70e23e2c..2d2a9ae7ea 100644 --- a/packages/router/src/create_url_tree.ts +++ b/packages/router/src/create_url_tree.ts @@ -186,7 +186,7 @@ function createPositionApplyingDoubleDots( return new Position(g, false, ci - dd); } -function getOutlets(commands: any[]): {[k: string]: any[]} { +function getOutlets(commands: unknown[]): {[k: string]: unknown[]|string} { if (isCommandWithOutlets(commands[0])) { return commands[0].outlets; } @@ -229,7 +229,10 @@ function updateSegmentGroupChildren( const outlets = getOutlets(commands); const children: {[key: string]: UrlSegmentGroup} = {}; - forEach(outlets, (commands: any, outlet: string) => { + forEach(outlets, (commands, outlet) => { + if (typeof commands === 'string') { + commands = [commands]; + } if (commands !== null) { children[outlet] = updateSegmentGroup(segmentGroup.children[outlet], startIndex, commands); } @@ -311,9 +314,13 @@ function createNewSegmentGroup( return new UrlSegmentGroup(paths, {}); } -function createNewSegmentChildren(outlets: {[name: string]: any}): any { - const children: {[key: string]: UrlSegmentGroup} = {}; - forEach(outlets, (commands: any, outlet: string) => { +function createNewSegmentChildren(outlets: {[name: string]: unknown[]|string}): + {[outlet: string]: UrlSegmentGroup} { + const children: {[outlet: string]: UrlSegmentGroup} = {}; + forEach(outlets, (commands, outlet) => { + if (typeof commands === 'string') { + commands = [commands]; + } if (commands !== null) { children[outlet] = createNewSegmentGroup(new UrlSegmentGroup([], {}), 0, commands); } diff --git a/packages/router/test/create_url_tree.spec.ts b/packages/router/test/create_url_tree.spec.ts index d51fa48d95..0826b2c6ff 100644 --- a/packages/router/test/create_url_tree.spec.ts +++ b/packages/router/test/create_url_tree.spec.ts @@ -206,6 +206,13 @@ describe('createUrlTree', () => { }); }); + it('can navigate to nested route where commands is string', () => { + const p = serializer.parse('/'); + const t = createRoot( + p, ['/', {outlets: {primary: ['child', {outlets: {primary: 'nested-primary'}}]}}]); + expect(serializer.serialize(t)).toEqual('/child/nested-primary'); + }); + it('should throw when outlets is not the last command', () => { const p = serializer.parse('/a'); expect(() => createRoot(p, ['a', {outlets: {right: ['c']}}, 'c']))