fix(router): stringify positional parameters when using routerLink
This commit is contained in:
parent
cf4a9236b9
commit
f8e8d22e4e
|
@ -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]));
|
||||
|
|
|
@ -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']);
|
||||
|
|
Loading…
Reference in New Issue