0
정상적인 등록/로그인 양식과 일부 다른 alt 페이지가있는 각도 앱을 만들고 싶습니다.각도 4 -보기 설정
내 문제는 다른보기를 제어하는 방법을 알지 못한다는 것입니다. 예를 들어 일반 사용자 유형으로 로그인 한 경우보기 1을 볼 수 있습니다.
다른 사용자 유형으로 로그인하면 다른보기와 다른보기가 나타납니다.
정상적인 등록/로그인 양식과 일부 다른 alt 페이지가있는 각도 앱을 만들고 싶습니다.각도 4 -보기 설정
내 문제는 다른보기를 제어하는 방법을 알지 못한다는 것입니다. 예를 들어 일반 사용자 유형으로 로그인 한 경우보기 1을 볼 수 있습니다.
다른 사용자 유형으로 로그인하면 다른보기와 다른보기가 나타납니다.
는이 같은 가드의 특정보기로 리디렉션 할 수 있습니다 :
사용 CanActivateChild
라우팅 파일에 children: []
구성 요소를 보호하기 위해, 그렇지 않으면 인터페이스 CanActivate
를 사용합니다. 적용된 로직은 동일하게 유지됩니다.
import {Injectable} from '@angular/core';
import {Router, CanActivateChild} from '@angular/router';
import {AuthenticationService} from '../services';
@Injectable()
export class LoginAuthGuard implements CanActivateChild {
constructor(private router: Router,
private authenticationService: AuthenticationService) {
}
canActivateChild(): boolean {
if (this.authenticationService.isLoggedIn()) {
if (**normal user type **) {
this.router.navigate(['/view1']);
} else {
this.router.navigate(['/view2']);
}
return true;
} else {
this.router.navigate(['/login']);
return false;
}
}
}
코드를 입력하십시오. –
시작해야하는 페이지 : https://angular.io/guide/router. 키워드 : "라우팅" –