| 61 | } |
| 62 | |
| 63 | @Injectable({providedIn: 'root'}) |
| 64 | class CustomReuseStrategy extends BaseRouteReuseStrategy { |
| 65 | storedHandles = new Map<Route, DetachedRouteHandle>(); |
| 66 | shouldDestroyMap = new Map<Route, boolean>(); |
| 67 | |
| 68 | override shouldDetach(route: ActivatedRouteSnapshot): boolean { |
| 69 | return ( |
| 70 | route.routeConfig?.path === 'home' || |
| 71 | route.routeConfig?.path === 'check' || |
| 72 | route.routeConfig?.path === 'child' |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | override store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void { |
| 77 | if (route.routeConfig?.path && handle) { |
| 78 | this.storedHandles.set(route.routeConfig, handle); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | override shouldAttach(route: ActivatedRouteSnapshot): boolean { |
| 83 | return !!route.routeConfig?.path && !!this.storedHandles.has(route.routeConfig); |
| 84 | } |
| 85 | |
| 86 | override retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null { |
| 87 | return this.storedHandles.get(route.routeConfig!) || null; |
| 88 | } |
| 89 | |
| 90 | retrieveStoredRouteHandles(): DetachedRouteHandle[] { |
| 91 | return Array.from(this.storedHandles.values()); |
| 92 | } |
| 93 | |
| 94 | override shouldDestroyInjector(route: Route): boolean { |
| 95 | // Default to true if not specified, so we don't block destruction by default |
| 96 | return this.shouldDestroyMap.has(route) ? this.shouldDestroyMap.get(route)! : true; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | let router: Router; |
| 101 | let strategy: CustomReuseStrategy; |
nothing calls this directly
no test coverage detected
searching dependent graphs…