123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { Injectable } from '@angular/core';
- import {
- CanActivate,
- CanActivateChild,
- CanDeactivate,
- CanLoad,
- Route,
- UrlSegment,
- ActivatedRouteSnapshot,
- RouterStateSnapshot,
- UrlTree
- } from '@angular/router';
- import { Observable } from 'rxjs';
- import { NzMessageService } from 'ng-zorro-antd/message';
- @Injectable({
- providedIn: 'root'
- })
- export class AuthAllGuard implements CanActivate, CanActivateChild, CanDeactivate<unknown>, CanLoad {
- constructor(private message: NzMessageService) { }
- canActivate(
- route: ActivatedRouteSnapshot,
- state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- // this.message.info('是否允许进入路由');
- return true;
- }
- canActivateChild(
- childRoute: ActivatedRouteSnapshot,
- state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- // this.message.info('等同 canActivate,只不过针对是所有子路由。');
- return true;
- }
- canDeactivate(
- component: unknown,
- currentRoute: ActivatedRouteSnapshot,
- currentState: RouterStateSnapshot,
- nextState?: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- // this.message.info('控制是否允许离开路由');
- return true;
- }
- canLoad(
- route: Route,
- segments: UrlSegment[]): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- // this.message.info('是否延迟加载整个模块');
- return true;
- }
- }
|