auth-all.guard.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Injectable } from '@angular/core';
  2. import {
  3. CanActivate,
  4. CanActivateChild,
  5. CanDeactivate,
  6. CanLoad,
  7. Route,
  8. UrlSegment,
  9. ActivatedRouteSnapshot,
  10. RouterStateSnapshot,
  11. UrlTree
  12. } from '@angular/router';
  13. import { Observable } from 'rxjs';
  14. import { NzMessageService } from 'ng-zorro-antd/message';
  15. @Injectable({
  16. providedIn: 'root'
  17. })
  18. export class AuthAllGuard implements CanActivate, CanActivateChild, CanDeactivate<unknown>, CanLoad {
  19. constructor(private message: NzMessageService) { }
  20. canActivate(
  21. route: ActivatedRouteSnapshot,
  22. state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
  23. // this.message.info('是否允许进入路由');
  24. return true;
  25. }
  26. canActivateChild(
  27. childRoute: ActivatedRouteSnapshot,
  28. state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
  29. // this.message.info('等同 canActivate,只不过针对是所有子路由。');
  30. return true;
  31. }
  32. canDeactivate(
  33. component: unknown,
  34. currentRoute: ActivatedRouteSnapshot,
  35. currentState: RouterStateSnapshot,
  36. nextState?: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
  37. // this.message.info('控制是否允许离开路由');
  38. return true;
  39. }
  40. canLoad(
  41. route: Route,
  42. segments: UrlSegment[]): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
  43. // this.message.info('是否延迟加载整个模块');
  44. return true;
  45. }
  46. }