import { RouteReuseStrategy , ActivatedRouteSnapshot , DetachedRouteHandle , } from '@angular/router' ; export class CustomRouteReuseStrategy implements RouteReuseStrategy { handlers : { [ key ] : DetachedRouteHandle ; } = { } ; shouldDetach ( route ) { return this . shouldReuse ( route ) || false ; } store ( route , handle ) { if ( this . shouldReuse ( route ) ) { this . setHandler ( route , handle ) ; } } shouldAttach ( route ) { return this . hasHandler ( route ) ; } retrieve ( route ) { return this . getHandler ( route ) ; } shouldReuseRoute ( future , curr ) { return ( future . routeConfig === curr . routeConfig || this . shouldReuse ( future ) ) ; } private shouldReuse ( route ) { return this . isReusable ( route ) ; } private isReusable ( route ) { return route . data && route . data . shouldReuse ; } private getKey ( route ) { return route . data . key ; } private setHandler ( route , handle ) { this . handlers [ this . getKey ( route ) ] = handle ; } private getHandler ( route ) { return this . handlers [ this . getKey ( route ) ] ; } private hasHandler ( route ) { return ! ! this . getHandler ( route ) ; } }