当我导航回相同的组件时,我开始了解Sticky Routes重新附加早期的组件数据。我已经通过查看此https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx博客https://plnkr.co/edit/KVlRi9PtPeOpvn8bECBi?p=preview实现了一个演示......是吗?可能具有应用条件,以便routerreusestrategy
仅适用于少数组件吗?
答案 0 :(得分:12)
您只需对原始解决方案进行少量修改:https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx
在您的路线中添加shouldDetach
标志:
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent, data: { shouldDetach: true } },
...
];
并修改shouldDetach
中的CustomReuseStrategy
方法:
public shouldDetach(route: ActivatedRouteSnapshot): boolean {
return route.data && (route.data as any).shouldDetach;
}
以下是您更新的plunker:https://plnkr.co/edit/otbZBuRmGYQXeY6b4Sfp?p=preview