당신은 관리자 또는 구성원 중 하나를 사용하여 경로를 정의 가드를 사용하고 경로의 수 :
[편집] 나는 이런 식으로 뭔가를 할 수 있습니다.
@Injectable()
export class AdminGuard implements CanActivate {
constructor(private _authService: AuthService, private _router: Router) { }
canActivate() {
if (!this._authService.isAdmin) {
this._router.navigate(['/']);
}
return this._authService.isAdmin;
}
}
AuthGuard :
이
export const routes: Routes = [
{ path: '', component: PublicComponent },
{ path: 'member', component: MemberComponent, canActivate: [AuthGuard]},
{ path: 'admin', component: AdminComponent canActivate: [AdminGuard]},
];
export const routing = RouterModule.forRoot(routes);
그런 다음 두 가드를 만들 : 그것은 당신의 요구에 맞도록
먼저 설치하여 노선이 당신이 그것을 확장 할 수 sould 매우 간단한 예입니다 회원 :
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private _authService: AuthService, private _router: Router) { }
canActivate() {
if (!this._authService.isAuthenticated) {
this._router.navigate(['/']);
}
return this._authService.isAuthenticated;
}
}
그리고 나서 mem의 상태를 유지하는 서비스가 필요합니다. 맥주. 공급자는 싱글 톤 (singleton)으로 이식되어 있으므로 값은 응용 프로그램을 통해 일관성을 유지합니다. 내가 길을 발견 https://angular.io/docs/ts/latest/guide/router.html
자식 배열에 "path : ''redirectTo : ..."를 넣는 것도 가능합니까? –
예. 모든 항목 내에서 redirectTo를 사용할 수 있습니다. – Scandinave