Advertisement
Guest User

Untitled

a guest
Jul 1st, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy} from '@angular/router';
  2. import {LogInComponent} from '../components/authorization/log-in/log-in.component';
  3.  
  4. export class CustomRouteReuseStrategy implements RouteReuseStrategy {
  5.     private handlers: { [key: string]: DetachedRouteHandle } = {};
  6.  
  7.     shouldDetach(route: ActivatedRouteSnapshot): boolean {
  8.         return true;
  9.     }
  10.  
  11.     store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
  12.         const url = route.url.join('/') || route.parent.url.join('/');
  13.  
  14.         this.handlers[url] = handle;
  15.     }
  16.  
  17.     shouldAttach(route: ActivatedRouteSnapshot): boolean {
  18.         if (route.component === LogInComponent) {
  19.             this.handlers = {};
  20.             return false;
  21.         }
  22.  
  23.         const url = route.url.join('/') || route.parent.url.join('/');
  24.  
  25.         return !!this.handlers[url];
  26.     }
  27.  
  28.     retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
  29.         return this.handlers[route.url.join('/') || route.parent.url.join('/')];
  30.     }
  31.  
  32.     shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
  33.         return future.routeConfig === curr.routeConfig;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement