diff --git a/modules/@angular/router/src/create_url_tree.ts b/modules/@angular/router/src/create_url_tree.ts index 1030409047..2c0ad768af 100644 --- a/modules/@angular/router/src/create_url_tree.ts +++ b/modules/@angular/router/src/create_url_tree.ts @@ -124,7 +124,7 @@ function findStartingPosition( } function getPath(command: any): any { - if (!(typeof command === 'string')) return command; + if (!(typeof command === 'string')) return command.toString(); const parts = command.toString().split(':'); return parts.length > 1 ? parts[1] : command; } @@ -202,6 +202,7 @@ function createNewSegment(segment: UrlSegment, startIndex: number, commands: any const paths = segment.pathsWithParams.slice(0, startIndex); let i = 0; while (i < commands.length) { + // if we start with an object literal, we need to reuse the path part from the segment if (i === 0 && (typeof commands[0] === 'object')) { const p = segment.pathsWithParams[startIndex]; paths.push(new UrlPathWithParams(p.path, commands[0])); diff --git a/modules/@angular/router/test/create_url_tree.spec.ts b/modules/@angular/router/test/create_url_tree.spec.ts index 5a602fe9e8..c810b7b699 100644 --- a/modules/@angular/router/test/create_url_tree.spec.ts +++ b/modules/@angular/router/test/create_url_tree.spec.ts @@ -20,6 +20,15 @@ describe('createUrlTree', () => { expect(serializer.serialize(t)).toEqual("/one/11/two/22"); }); + + it("should stringify positional parameters", () => { + const p = serializer.parse("/a/b"); + const t = createRoot(p, ["/one", 11]); + const params = t.root.children[PRIMARY_OUTLET].pathsWithParams; + expect(params[0].path).toEqual("one"); + expect(params[1].path).toEqual("11"); + }); + it("should preserve secondary segments", () => { const p = serializer.parse("/a/11/b(right:c)"); const t = createRoot(p, ["/a", 11, 'd']);