fix(router): add segmentPath to the link DSL
This commit is contained in:
@ -101,17 +101,21 @@ function normalizeCommands(commands: any[]): NormalizedNavigationCommands {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof c === 'object' && c.segmentPath !== undefined) {
|
||||
res.push(c.segmentPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(typeof c === 'string')) {
|
||||
res.push(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
const parts = c.split('/');
|
||||
for (let j = 0; j < parts.length; ++j) {
|
||||
let cc = parts[j];
|
||||
if (i === 0) {
|
||||
const parts = c.split('/');
|
||||
for (let j = 0; j < parts.length; ++j) {
|
||||
let cc = parts[j];
|
||||
|
||||
// first exp is treated in a special way
|
||||
if (i == 0) {
|
||||
if (j == 0 && cc == '.') { // './a'
|
||||
// skip it
|
||||
} else if (j == 0 && cc == '') { // '/a'
|
||||
@ -121,12 +125,9 @@ function normalizeCommands(commands: any[]): NormalizedNavigationCommands {
|
||||
} else if (cc != '') {
|
||||
res.push(cc);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (cc != '') {
|
||||
res.push(cc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,9 +220,14 @@ export class Router {
|
||||
* // create /team/33;expand=true/user/11
|
||||
* router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
|
||||
*
|
||||
* // you can collapse static fragments like this
|
||||
* // you can collapse static segments like this (this works only with the first passed-in value):
|
||||
* router.createUrlTree(['/team/33/user', userId]);
|
||||
*
|
||||
* If the first segment can contain slashes, and you do not want the router to split it, you
|
||||
* can do the following:
|
||||
*
|
||||
* router.createUrlTree([{segmentPath: '/one/two'}]);
|
||||
*
|
||||
* // create /team/33/(user/11//aux:chat)
|
||||
* router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: 'chat'}}]);
|
||||
*
|
||||
|
@ -225,19 +225,24 @@ function serializeSegment(segment: UrlSegmentGroup, root: boolean): string {
|
||||
}
|
||||
}
|
||||
|
||||
export function encode(s: string): string {
|
||||
return encodeURIComponent(s);
|
||||
}
|
||||
|
||||
export function decode(s: string): string {
|
||||
return decodeURIComponent(s);
|
||||
}
|
||||
|
||||
export function serializePath(path: UrlSegment): string {
|
||||
return `${encodeURIComponent(path.path)}${serializeParams(path.parameters)}`;
|
||||
return `${encode(path.path)}${serializeParams(path.parameters)}`;
|
||||
}
|
||||
|
||||
function serializeParams(params: {[key: string]: string}): string {
|
||||
return pairs(params)
|
||||
.map(p => `;${encodeURIComponent(p.first)}=${encodeURIComponent(p.second)}`)
|
||||
.join('');
|
||||
return pairs(params).map(p => `;${encode(p.first)}=${encode(p.second)}`).join('');
|
||||
}
|
||||
|
||||
function serializeQueryParams(params: {[key: string]: string}): string {
|
||||
const strs =
|
||||
pairs(params).map(p => `${encodeURIComponent(p.first)}=${encodeURIComponent(p.second)}`);
|
||||
const strs = pairs(params).map(p => `${encode(p.first)}=${encode(p.second)}`);
|
||||
return strs.length > 0 ? `?${strs.join("&")}` : '';
|
||||
}
|
||||
|
||||
@ -348,7 +353,7 @@ class UrlParser {
|
||||
if (this.peekStartsWith(';')) {
|
||||
matrixParams = this.parseMatrixParams();
|
||||
}
|
||||
return new UrlSegment(decodeURIComponent(path), matrixParams);
|
||||
return new UrlSegment(decode(path), matrixParams);
|
||||
}
|
||||
|
||||
parseQueryParams(): {[key: string]: any} {
|
||||
@ -366,7 +371,7 @@ class UrlParser {
|
||||
|
||||
parseFragment(): string {
|
||||
if (this.peekStartsWith('#')) {
|
||||
return decodeURIComponent(this.remaining.substring(1));
|
||||
return decode(this.remaining.substring(1));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -397,7 +402,7 @@ class UrlParser {
|
||||
}
|
||||
}
|
||||
|
||||
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
||||
params[decode(key)] = decode(value);
|
||||
}
|
||||
|
||||
parseQueryParam(params: {[key: string]: any}): void {
|
||||
@ -415,7 +420,7 @@ class UrlParser {
|
||||
this.capture(value);
|
||||
}
|
||||
}
|
||||
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
||||
params[decode(key)] = decode(value);
|
||||
}
|
||||
|
||||
parseParens(allowPrimary: boolean): {[key: string]: UrlSegmentGroup} {
|
||||
|
Reference in New Issue
Block a user