내 응용 프로그램에는 AppModule과 UserModule이라는 두 가지 기능이 있습니다.각도 2 인증 : 사용자 페이지에 로그 아웃 유지
UserModule - 로그인 한 사용자의 경우.
AppModule - 로그인 페이지.
내 auth.service
에 대한 인증을 관리하고 있으며 또한 auth.guard.service
으로 경비가 있습니다.
auth.service.logOut()
으로 전화하면 사용자는 로그 아웃되지만 패널에 남아 있으며 경로는 변경되지 않습니다. 또한 this.router.navigate(['']);
을 추가하려고했지만 사용자가 /panel
경로에 머물러 있습니다.
이 내 로그 아웃 방법 :
logout() {
console.log("logging out..");
this.auth.logout();
this.userData = null;
this.isLoggedIn = false;
this.router.navigate(['']);
}
내 PanelComponent
내부에이 메소드를 호출합니다. 문제는 사용자가 PanelComponent에 머물러 있고 로그인 페이지 인 HomeComponent
으로 "걷어차 지"않습니다.
는
@NgModule({
imports: [
RouterModule.forRoot([
{ path: '', component: HomeComponent },
])
],
exports: [
RouterModule
]
})
사용자 panel.routing.module.ts
@NgModule({
imports: [
RouterModule.forChild([
{
path: 'panel',
component: PanelComponent,
canActivate: [AuthGuard],
children: [
{
path: '',
children: [
{ path: 'userHome', component: userHomeComponent },
{ path: '', component: PanelHomeComponent }
]
}
]
}
])
],
내 페이지를 새로 고침
app.routing.module.ts, 내가 다시 로그인을 옮겼다하고 있습니다. 상쾌하게하지 않으면 왜 효과가 없습니까?업데이트 : isLoggedIn
변수가 변경되었지만 집에서 나를 다시 패널로 리디렉션합니다.
내 HomeComponent가 나를 다시 내 패널로 리디렉션하고 있지만 그렇지 않아야합니다.
는 HomeComponent : 내 로그 아웃() 메소드에
ngOnInit() {
//If he is alredy logged, redirect him to the panel
this.authService.login().subscribe(() => {
this.loaded = true;
if (this.authService.isLoggedIn) {
console.log("Navigated back to worker panel!");
this.router.navigate(['/worker-panel']);
}
});
나는 false
내 isLoggedIn
변수를 설정하십시오. Navigated back to worker panel!
라우터 구성을 추가하십시오. –
안녕하세요 @ GünterZöchbauer 내 패널 모듈 라우터를 추가했습니다. AuthGuard를 내 모듈 (기능)에 두었습니다. – TheUnreal
'auth.service.logOut()'을 호출 할 때 어떤 경로가 활성화되어 있습니까? 예상되는 행동은 무엇입니까? 상위 라우터 구성도 추가하십시오. –