Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. // In app.module.ts
  2. providers: [
  3. {provide: RouteReuseStrategy, useClass: CustomReuseStrategy}
  4. ]
  5.  
  6. // In custom.reuse.strategy.ts
  7. import {ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy} from '@angular/router';
  8.  
  9. export class CustomReuseStrategy implements RouteReuseStrategy {
  10. routesToCache: string[] = ['users'];
  11. storedRouteHandles = new Map<string, DetachedRouteHandle>();
  12.  
  13. shouldDetach(route: ActivatedRouteSnapshot): boolean {
  14. return this.routesToCache.indexOf(route.routeConfig.path) > -1;
  15. }
  16.  
  17. store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
  18. this.storedRouteHandles.set(route.routeConfig.path, handle);
  19. }
  20.  
  21. shouldAttach(route: ActivatedRouteSnapshot): boolean {
  22. return this.storedRouteHandles.has(route.routeConfig.path);
  23. }
  24.  
  25. retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
  26. return this.storedRouteHandles.get(route.routeConfig.path);
  27. }
  28.  
  29. shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
  30. return future.routeConfig === curr.routeConfig;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement