Использование 2 охранников для 1 маршрута в Авгуларе не работает - PullRequest
0 голосов
/ 28 февраля 2019

Я создал 3 разных сторожа: StudentsGuard TeachersGuard AdminsGuard

Я хочу, чтобы Admins Guard и Student Guard оба позволили доступ к компоненту студента, но по какой-то причине AdminGuard не может связаться с компонентом студента.

Мои стражи:

// StudentGuard:

 export class StudentAuthGuard implements CanActivateChild {
  constructor(private sauthService: StudentAuthService, private alertify: AlertifyService,
      private router: Router) {}
  canActivateChild(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot) {
    if (this.sauthService.isStudentLoggedIn()) {
      return true;
    } else {
      this.router.navigate(['/home']);
      this.alertify.error('Access Denied');
    }
  }
}

// TeachersGuard:

  export class TeacherAuthGuard implements CanActivateChild {
  constructor(private sauthService: StudentAuthService, private alertify: AlertifyService,
    private router: Router) {}
canActivateChild(
  next: ActivatedRouteSnapshot,
  state: RouterStateSnapshot) {
  if (this.sauthService.isTeacherLoggedIn()) {
    return true;
  } else {
    this.router.navigate(['/home']);
    this.alertify.error('Access Denied');
  }
}
}

// AdminGuard

 export class AdminAuthGuard implements CanActivateChild {
  constructor(private sauthService: StudentAuthService, private alertify: AlertifyService,
    private router: Router) {}
canActivateChild(
  next: ActivatedRouteSnapshot,
  state: RouterStateSnapshot) {
  if (this.sauthService.isAdminLoggedIn()) {
    return true;
  } else {
    this.router.navigate(['/home']);
    this.alertify.error('Access Denied');
  }
}
}

// Модуль маршрутизации:

  const appRoutes: Routes = [
  {path: '', redirectTo: '/home', pathMatch: 'full'},
  {path: 'login', component: StudentLoginComponent},
  {path: 'teachersLogin', component: TeacherLoginComponent},
  {path: 'adminLogin', component: AdminLoginComponent},
  {path: 'home', component: HomeComponent},
  {path: 'about-us', component: AboutComponent},
  {
    path: '',
    canActivateChild: [StudentAuthGuard],
    children: [
      {path: 'myAttendance', component: MyAttendanceComponent}
    ]
  },
  {
    path: '',
    canActivateChild: [TeacherAuthGuard],
    children: [
      {path: 'studentList', component: StudentListComponent},
      {path: 'studentCreate', component: StudentCreateComponent},
      {path: 'studentCreate/:id', component: StudentCreateComponent},
      {path: 'fillAttendance', component: AttendanceFillComponent},
    ]
  },
  {
    path: '',
    canActivateChild: [AdminAuthGuard],
    children: [
      {path: 'studentList', component: StudentListComponent},
      {path: 'studentCreate', component: StudentCreateComponent},
      {path: 'studentCreate/:id', component: StudentCreateComponent},
      {path: 'teacherList', component: TeacherListComponent},
      {path: 'teacherCreate', component: TeacherCreateComponent},
      {path: 'teacherCreate/:id', component: TeacherCreateComponent}
    ]
  }
];

Пожалуйста, помогите, я не могу понять, что происходит не так

...