当我导航回相同的组件时,我开始了解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 …是否可以使用apply条件以便routerreusestrategy仅适用少数组件?
您只需要对原始解决方案进行微小修改:
https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx
原文链接:https://www.f2er.com/angularjs/142264.html将shouldDetach标志添加到您的路线:
const appRoutes: Routes = [ { path: 'crisis-center',component: CrisisListComponent,data: { shouldDetach: true } },... ];
并修改CustomReuseStrategy中的shouldDetach方法:
public shouldDetach(route: ActivatedRouteSnapshot): boolean { return route.data && (route.data as any).shouldDetach; }
这是你的plunker更新:https://plnkr.co/edit/otbZBuRmGYQXeY6b4Sfp?p=preview