合并为一个项目 #14

Merged
xiaohai2271 merged 56 commits from issue11 into master 2020-05-16 22:35:08 +08:00
2 changed files with 4 additions and 1 deletions
Showing only changes of commit b45f3f16e3 - Show all commits

View File

@@ -8,7 +8,7 @@ const routes: Routes = [
{
path: '',
component: AdminComponent,
canActivate: [AuthGuard],
// canActivate: [AuthGuard],
children: [
{
path: 'article',

View File

@@ -14,12 +14,14 @@ export class AuthGuard implements CanActivate {
}
userInfo: User;
visitCount: number = 0; // 记录一共走过几次canActivate
private path: string;
private readonly loginPath: string = '/user/login';
private observable: Observable<boolean>;
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
this.path = state.url.indexOf('?') > 0 ? state.url.substr(0, state.url.indexOf('?')) : state.url;
this.visitCount++;
this.observable = new Observable<boolean>(observer => {
if (!this.userInfo) {
this.watchUserInfo(observer);
@@ -58,6 +60,7 @@ export class AuthGuard implements CanActivate {
case '/admin/visitor':
if (this.userInfo.role !== 'admin') {
observer.next(false)
if (this.visitCount === 1) this.router.navigateByUrl('/admin')
return;
}
}