fix(router): redirect should not add unnecessary brackets
This commit is contained in:
@ -235,19 +235,28 @@ function split(
|
||||
const s = new UrlSegment(
|
||||
consumedPaths,
|
||||
createChildrenForEmptyPaths(config, new UrlSegment(slicedPath, segment.children)));
|
||||
return {segment: s, slicedPath: []};
|
||||
return {segment: mergeTrivialChildren(s), slicedPath: []};
|
||||
|
||||
} else if (slicedPath.length === 0 && containsEmptyPathRedirects(segment, slicedPath, config)) {
|
||||
const s = new UrlSegment(
|
||||
segment.pathsWithParams,
|
||||
addEmptyPathsToChildrenIfNeeded(segment, slicedPath, config, segment.children));
|
||||
return {segment: s, slicedPath};
|
||||
return {segment: mergeTrivialChildren(s), slicedPath};
|
||||
|
||||
} else {
|
||||
return {segment, slicedPath};
|
||||
}
|
||||
}
|
||||
|
||||
function mergeTrivialChildren(s: UrlSegment): UrlSegment {
|
||||
if (s.numberOfChildren === 1 && s.children[PRIMARY_OUTLET]) {
|
||||
const c = s.children[PRIMARY_OUTLET];
|
||||
return new UrlSegment(s.pathsWithParams.concat(c.pathsWithParams), c.children);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
function addEmptyPathsToChildrenIfNeeded(
|
||||
segment: UrlSegment, slicedPath: UrlPathWithParams[], routes: Route[],
|
||||
children: {[name: string]: UrlSegment}): {[name: string]: UrlSegment} {
|
||||
|
@ -96,7 +96,15 @@ export class UrlSegment {
|
||||
forEach(children, (v: any, k: any) => v.parent = this);
|
||||
}
|
||||
|
||||
hasChildren(): boolean { return Object.keys(this.children).length > 0; }
|
||||
/**
|
||||
* Return true if the segment has child segments
|
||||
*/
|
||||
hasChildren(): boolean { return this.numberOfChildren > 0; }
|
||||
|
||||
/**
|
||||
* Returns the number of child sements.
|
||||
*/
|
||||
get numberOfChildren(): number { return Object.keys(this.children).length; }
|
||||
|
||||
toString(): string { return serializePaths(this); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user