Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In app.module.ts
- providers: [
- {provide: RouteReuseStrategy, useClass: CustomReuseStrategy}
- ]
- // In custom.reuse.strategy.ts
- import {ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy} from '@angular/router';
- export class CustomReuseStrategy implements RouteReuseStrategy {
- routesToCache: string[] = ['users'];
- storedRouteHandles = new Map<string, DetachedRouteHandle>();
- shouldDetach(route: ActivatedRouteSnapshot): boolean {
- return this.routesToCache.indexOf(route.routeConfig.path) > -1;
- }
- store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
- this.storedRouteHandles.set(route.routeConfig.path, handle);
- }
- shouldAttach(route: ActivatedRouteSnapshot): boolean {
- return this.storedRouteHandles.has(route.routeConfig.path);
- }
- retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
- return this.storedRouteHandles.get(route.routeConfig.path);
- }
- shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
- return future.routeConfig === curr.routeConfig;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement