-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp-routing.cache.ts
36 lines (35 loc) · 1.29 KB
/
app-routing.cache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
RouteReuseStrategy,
ActivatedRouteSnapshot,
DetachedRouteHandle
} from "@angular/router";
export class AppRoutingCache implements RouteReuseStrategy {
public static handlers: {[key: string]: DetachedRouteHandle} = {};
static getRouteSnapshotUrl(route: ActivatedRouteSnapshot): string {
return route['_routerState'].url;
}
shouldDetach(route: ActivatedRouteSnapshot): boolean {
console.log('shouldDetach');
return true;
}
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void {
console.log('store', handle);
AppRoutingCache.handlers[AppRoutingCache.getRouteSnapshotUrl(route)] = handle;
}
shouldAttach(route: ActivatedRouteSnapshot): boolean {
console.log('shouldAttach');
return !!AppRoutingCache.handlers[AppRoutingCache.getRouteSnapshotUrl(route)];
}
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null {
console.log('retrieve', route.routeConfig && route.routeConfig.path);
if (!route.routeConfig) {
return null;
}
const path = AppRoutingCache.getRouteSnapshotUrl(route);
return AppRoutingCache.handlers[path];
}
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
console.log('shouldReuseRoute', future, curr);
return false;
}
}