0
내 코드는 작동하지만 작동하지 않습니다. 경로로드 전에 사용자 정보를 확인하고 싶습니다. 3.4.2해결사로 각도 2 라우터 전송 데이터가 작동하지 않습니다.
확인자 클래스 :
이@Injectable()
export class UserRoleResolver implements Resolve<any> {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any {
let user:any = {};
user.role = 'MEMBER';
return user;
}
}
라우터 :
이export const APP_ROUTES: Routes = [
{path: '', component: PublicComponent, children: PUBLIC_ROUTES},
{
path: '',
component: SecureComponent,
resolve: {userRole: UserRoleResolver},
canActivate: [AuthGuard],
children: SECURE_ROUTES
}
];
안전 구성 요소 : 나는 각도/라우터 @ 사용
export class SecureComponent implements OnInit {
userRole:any;
role:string = 'MEMBER';
constructor(private userService: UserService,private router:Router) {
}
ngOnInit() {
this.role = 'MEMBER';
console.log('Role',this.userRole);
if (!this.userService.isLoggedIn()) {
this.router.navigateByUrl('/login');
}
}
}