fix(router): always stringify matrix parameters (#25095)

Fix a case where matrix parameters weren't stringified when they are passed as a first command
when creating a url tree. Fix return type in parseMatrixParams method
because it always returns {[key: string]: string}

Closes #23165

PR Close #25095
This commit is contained in:
Alex Mokin 2018-07-25 02:20:34 +03:00 committed by Jessica Janiuk
parent 51d6aed677
commit 3cf4e3c7c5
3 changed files with 16 additions and 4 deletions

View File

@ -296,7 +296,7 @@ function createNewSegmentGroup(
// if we start with an object literal, we need to reuse the path part from the segment
if (i === 0 && isMatrixParams(commands[0])) {
const p = segmentGroup.segments[startIndex];
paths.push(new UrlSegment(p.path, commands[0]));
paths.push(new UrlSegment(p.path, stringify(commands[0])));
i++;
continue;
}

View File

@ -522,15 +522,15 @@ class UrlParser {
return new UrlSegment(decode(path), this.parseMatrixParams());
}
private parseMatrixParams(): {[key: string]: any} {
const params: {[key: string]: any} = {};
private parseMatrixParams(): {[key: string]: string} {
const params: {[key: string]: string} = {};
while (this.consumeOptional(';')) {
this.parseParam(params);
}
return params;
}
private parseParam(params: {[key: string]: any}): void {
private parseParam(params: {[key: string]: string}): void {
const key = matchSegments(this.remaining);
if (!key) {
return;

View File

@ -267,6 +267,18 @@ describe('createUrlTree', () => {
expect(serializer.serialize(t)).toEqual('/a/b;aa=22;bb=33');
});
it('should stringify matrix parameters', () => {
const pr = serializer.parse('/r');
const relative = create(pr.root.children[PRIMARY_OUTLET], 0, pr, [{pp: 22}]);
const segmentR = relative.root.children[PRIMARY_OUTLET].segments[0];
expect(segmentR.parameterMap.get('pp')).toEqual('22');
const pa = serializer.parse('/a');
const absolute = createRoot(pa, ['/b', {pp: 33}]);
const segmentA = absolute.root.children[PRIMARY_OUTLET].segments[0];
expect(segmentA.parameterMap.get('pp')).toEqual('33');
});
describe('relative navigation', () => {
it('should work', () => {
const p = serializer.parse('/a/(c//left:cp)(left:ap)');