Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/router/src/create_url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export function createUrlTree(
route: ActivatedRoute, urlTree: UrlTree, commands: any[], queryParams: Params|null,
fragment: string|null): UrlTree {
if (commands.length === 0) {
return tree(urlTree.root, urlTree.root, urlTree, queryParams, fragment);
return tree(urlTree.root, urlTree.root, urlTree.root, queryParams, fragment);
}

const nav = computeNavigation(commands);

if (nav.toRoot()) {
return tree(urlTree.root, new UrlSegmentGroup([], {}), urlTree, queryParams, fragment);
return tree(urlTree.root, urlTree.root, new UrlSegmentGroup([], {}), queryParams, fragment);
}

const startingPosition = findStartingPosition(nav, urlTree, route);
Expand All @@ -30,7 +30,7 @@ export function createUrlTree(
updateSegmentGroupChildren(
startingPosition.segmentGroup, startingPosition.index, nav.commands) :
updateSegmentGroup(startingPosition.segmentGroup, startingPosition.index, nav.commands);
return tree(startingPosition.segmentGroup, segmentGroup, urlTree, queryParams, fragment);
return tree(urlTree.root, startingPosition.segmentGroup, segmentGroup, queryParams, fragment);
}

function isMatrixParams(command: any): boolean {
Expand All @@ -46,7 +46,7 @@ function isCommandWithOutlets(command: any): command is {outlets: {[key: string]
}

function tree(
oldSegmentGroup: UrlSegmentGroup, newSegmentGroup: UrlSegmentGroup, urlTree: UrlTree,
oldRoot: UrlSegmentGroup, oldSegmentGroup: UrlSegmentGroup, newSegmentGroup: UrlSegmentGroup,
queryParams: Params|null, fragment: string|null): UrlTree {
let qp: any = {};
if (queryParams) {
Expand All @@ -55,11 +55,12 @@ function tree(
});
}

if (urlTree.root === oldSegmentGroup) {
if (oldRoot === oldSegmentGroup) {
return new UrlTree(newSegmentGroup, qp, fragment);
}

return new UrlTree(replaceSegment(urlTree.root, oldSegmentGroup, newSegmentGroup), qp, fragment);
const newRoot = replaceSegment(oldRoot, oldSegmentGroup, newSegmentGroup);
return new UrlTree(newRoot, qp, fragment);
}

function replaceSegment(
Expand Down