I want to use this custom route reuse strategy for just one module:
export class CustomRouteReuseStrategy extends Ro
I finally achieved it by passing a bit modified CustomRouteStrategy to AppModule:
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 (future.routeConfig === curr.routeConfig) || future.data.reuse;
}
}
And adding data: { reuse: true } to the routing of lazily loaded ChildModule:
{
path: 'some-path',
data: { reuse: true },
loadChildren: './child.module#ChildModule',
},
Demo with more advanced solution