Skip to content

RouteReuseStrategy.retrieve() gets called twice in a row #22474

@sliekens

Description

@sliekens

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.

// 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+

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions