fix(router): cache route handle if found (#22475)

When asking the route reuse strategy to retrieve a detached route handle, store the
return value in a local variable for further processing instead of asking again later.

resolves #22474

PR Close #22475
This commit is contained in:
Steven Liekens
2018-02-27 15:04:36 +01:00
committed by Victor Berchet
parent 999ab0a690
commit 4cfa571258
2 changed files with 33 additions and 9 deletions

View File

@ -30,16 +30,19 @@ function createNode(
return new TreeNode<ActivatedRoute>(value, children);
// retrieve an activated route that is used to be displayed, but is not currently displayed
} else if (routeReuseStrategy.retrieve(curr.value)) {
const tree: TreeNode<ActivatedRoute> =
(<DetachedRouteHandleInternal>routeReuseStrategy.retrieve(curr.value)).route;
setFutureSnapshotsOfActivatedRoutes(curr, tree);
return tree;
} else {
const value = createActivatedRoute(curr.value);
const children = curr.children.map(c => createNode(routeReuseStrategy, c));
return new TreeNode<ActivatedRoute>(value, children);
const detachedRouteHandle =
<DetachedRouteHandleInternal>routeReuseStrategy.retrieve(curr.value);
if (detachedRouteHandle) {
const tree: TreeNode<ActivatedRoute> = detachedRouteHandle.route;
setFutureSnapshotsOfActivatedRoutes(curr, tree);
return tree;
} else {
const value = createActivatedRoute(curr.value);
const children = curr.children.map(c => createNode(routeReuseStrategy, c));
return new TreeNode<ActivatedRoute>(value, children);
}
}
}