我只想对一个模块使用这种自定义路由重用策略:
export class CustomRouteReuseStrategy extends RouteReuseStrategy {
public shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; }
public store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
public shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; }
public retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { return null; }
public shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
return true;
}
}
所以我在我的一个名为的模块中传递了@NgModule() ChildModule
:
providers: [
{
provide: RouteReuseStrategy,
useClass: CustomRouteReuseStrategy
}
]
不幸的是,当我将它传递到那里时,它就会被忽略。虽然添加到我的根目录时工作正常AppModule
......我不确定它是否重要,但ChildModule
被懒惰地加载。如何解决?