我使用 ngx admin 創建使用 nebular 的管理面板,我按照這個文檔添加 authGard:docs這可以自定義登錄:docs2所有的事情都是真實的,我得到了成功的信息:但我在 autogard 中弄錯了:我使用的代碼:@NgModule({ declarations: [ AppComponent, ], providers: [ AuthGuard, ], imports: [ *** ], bootstrap: [AppComponent],})export class AppModule {}//**********@Injectable()export class AuthGuard implements CanActivate { constructor(private authService: NbAuthService, private router: Router) { } canActivate() { console.log(this.authService.isAuthenticated()); return this.authService.isAuthenticated() .pipe( tap(authenticated => { if (!authenticated) { console.log(authenticated); this.router.navigate(['auth/login']); } }), ); }}//**********const routes: Routes = [ { path: 'pages', canActivate: [AuthGuard], loadChildren: () => import('./pages/pages.module') .then(m => m.PagesModule), }, { path: 'auth', loadChildren: () => import('./auth/auth.module').then(m => m.NgxAuthModule), }, { path: '', redirectTo: 'pages', pathMatch: 'full' }, { path: '**', redirectTo: 'pages' },];
AuthGuard 在星云中總是錯誤的
呼如林
2022-05-26 15:34:26