当我导航回相同的组件时,我开始了解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
仅适用于少数几个组件?
You need only minor modification of the original solution: https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx
Add shouldDetach
flag to your route:
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent, data: { shouldDetach: true } },
...
];
And modify shouldDetach
method in CustomReuseStrategy
:
public shouldDetach(route: ActivatedRouteSnapshot): boolean {
return route.data && (route.data as any).shouldDetach;
}
Here is your plunker updated: https://plnkr.co/edit/otbZBuRmGYQXeY6b4Sfp?p=preview
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.