import { RouteReuseStrategy , ActivatedRouteSnapshot , DetachedRouteHandle } from '@angular/router' ; import { Injectable } from '@angular/core' ; /**
 * This makes each route with the 'reuse' data flag persist when not in focus.
 */ @ Injectable ( ) export class TabPersistStrategy extends RouteReuseStrategy { private handles : { [ path ] : DetachedRouteHandle ; } = { } ; shouldDetach ( route ) { return route . data . shouldReuse || false ; } store ( route , handle ) { if ( route . data . shouldReuse ) { this . handles [ route . routeConfig . path ] = handle ; } } shouldAttach ( route ) { return ! ! route . routeConfig && ! ! this . handles [ route . routeConfig . path ] ; } retrieve ( route ) { if ( ! route . routeConfig ) return null ; return this . handles [ route . routeConfig . path ] ; } shouldReuseRoute ( future ) { return future . data . shouldReuse || false ; } }