我有2个型号:AppModule,PanelModule .
在我的AppComponent中,我检查用户是否已登录,如果是,则将其重定向到面板 . 这就是我这样做的方式:
ngOnInit() {
//If he is alredy logged, redirect him to the panel
this.authService.login().subscribe(() => {
this.authService.loaded = true;
if (this.authService.isLoggedIn) {
console.log("Navigating to panel..");
this.router.navigate(['/panel']);
}
});
}
当我的位置是儿童路线时,问题就开始了 . 例如:
/panel/users
如果我试图直接访问URL,我会导航回 /panel
,因为用户已登录并且 this.router.navigate(['/panel']);
已执行 .
什么是正确的方法,以便我的应用程序将用户重定向到正确的路径?
1 回答
您可能只想订阅第一个结果: