小编Bam*_*ami的帖子

Angular - 如何解决 Angular-15 Auth Guard 中弃用的 CanActivate

我将 Angular-14 代码升级到 Angular-15。然后我有这个代码:

授权卫士:

import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { ToastrService } from 'ngx-toastr';
import { AuthService } from 'src/app/features/auth/services/auth.service';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class AuthGuard implements CanActivate {

  constructor(private authService: AuthService, private toastr: ToastrService, private router: Router) { }
  canActivate(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ):
    | Observable<boolean | UrlTree>
    | Promise<boolean | UrlTree> …
Run Code Online (Sandbox Code Playgroud)

angular

27
推荐指数
0
解决办法
6万
查看次数

标签 统计

angular ×1