From fe21eff54c6ecd60de7f3eb1a0c9bfab6615f9a0 Mon Sep 17 00:00:00 2001 From: SHAOJIAHAO <55341701@qq.com> Date: Thu, 25 Nov 2021 13:38:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=E8=B7=AF=E7=94=B1=E5=AE=88?= =?UTF-8?q?=E5=8D=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app-routing.module.ts | 4 ++-- src/app/auth.guard.ts | 14 +++++++------- .../navigation/navigation.component.html | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 62ab6f4..a8272e8 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -15,12 +15,12 @@ const routes: Routes = [ { path: 'login', component: LoginComponent }, //登录页 { path: 'register', component: RegisterComponent }, //注册页 { - path: '', component: HomeComponent, children: [ + path: '', component: HomeComponent, canActivate: [AuthGuard], children: [ { path: '', loadChildren: () => import('./pages/pages.module').then(m => m.PagesModule) } ] }, //首页 { - path: '', component: NavigationComponent, children: [ + path: '', component: NavigationComponent, canActivate: [AuthGuard], children: [ { path: 'system', loadChildren: () => import('./system-management/system-management.module').then(m => m.SystemManagementModule) } ] }//系统管理 diff --git a/src/app/auth.guard.ts b/src/app/auth.guard.ts index ac887e4..af4d216 100644 --- a/src/app/auth.guard.ts +++ b/src/app/auth.guard.ts @@ -14,17 +14,17 @@ export class AuthGuard implements CanActivate { // 路由守卫 canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { - console.log('路由守卫',next.data) - if(next.data.permission == 'xxxx'){ - return true; - } - // return this.checkLogin(); + // console.log('路由守卫',next.data) + // if(next.data.permission == 'xxxx'){ + // return true; + // } + return this.checkLogin(); } checkLogin(): boolean { - + console.log('xxxxxxxxxxxx') // 判断本地有没有token - const token = this.cookieService.get("token"); + const token = this.cookieService.get("token") || sessionStorage.getItem('token'); // 如果有token,允许访问 if (token) { return true; } diff --git a/src/app/system-management/navigation/navigation.component.html b/src/app/system-management/navigation/navigation.component.html index a839689..bdda0a2 100644 --- a/src/app/system-management/navigation/navigation.component.html +++ b/src/app/system-management/navigation/navigation.component.html @@ -2,7 +2,7 @@