canActivate - 减慢应用程序。什么时候调用它?

canActivate - slows down the app. When to call it?

我有一个带有 .net 核心后端的 angular 应用程序。我正在为用户 authorization/identification 使用 windows 活动目录。一切正常,但我感觉该应用程序运行缓慢...我已确认发生这种情况,因为我正在检查每个组件加载时用户是否有效。

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> {
    if (this.auth.isAuthenticated) {
       return true;
    } else {
       return this.router.parseUrl('/notAuthorized');
    }
});

"isAuthenticated" 是一种调用后端并检查用户是否有效的方法。

那么,关于处理这种情况的最佳做法有什么建议吗?

由于每条路由上的服务器调用,它正在变慢,您可以将您的 AuthSession 存储在会话存储中并检查 Session 是否存在