mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 22:29:38 +00:00
30 lines
972 B
TypeScript
30 lines
972 B
TypeScript
import { Injectable } from '@angular/core'
|
|
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router'
|
|
|
|
/**
|
|
* This makes each route with the 'reuse' data flag persist when not in focus.
|
|
*/
|
|
@Injectable()
|
|
export class TabPersistStrategy extends RouteReuseStrategy {
|
|
private handles: { [path: string]: DetachedRouteHandle } = {}
|
|
|
|
shouldDetach(route: ActivatedRouteSnapshot) {
|
|
return route.data.shouldReuse || false
|
|
}
|
|
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle) {
|
|
if (route.data.shouldReuse) {
|
|
this.handles[route.routeConfig!.path!] = handle
|
|
}
|
|
}
|
|
shouldAttach(route: ActivatedRouteSnapshot) {
|
|
return !!route.routeConfig && !!this.handles[route.routeConfig!.path!]
|
|
}
|
|
retrieve(route: ActivatedRouteSnapshot) {
|
|
if (!route.routeConfig) return null
|
|
return this.handles[route.routeConfig!.path!]
|
|
}
|
|
shouldReuseRoute(future: ActivatedRouteSnapshot) {
|
|
return future.data.shouldReuse || false
|
|
}
|
|
}
|