-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Closed
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The routeReuseStrategy.retrieve(curr.value)
is called twice in a row when creating the router state.
angular/packages/router/src/create_router_state.ts
Lines 32 to 44 in c8a1a14
// 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); | |
} | |
} |
Expected behavior
Call retrieve
once and reuse the return value.
} else {
// retrieve an activated route that is used to be displayed, but is not currently displayed
const detachedHandle: DetachedRouteHandleInternal = routeReuseStrategy.retrieve(curr.value);
if (detachedHandle) {
const tree: TreeNode<ActivatedRoute> = detachedHandle.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);
}
}
What is the motivation / use case for changing the behavior?
The current behavior confuses me as an implementer of the RouteReuseStrategy
interface.
Environment
Angular version: 2.3+
sliekens, albanx and dmkuba