【发布时间】:2017-02-26 13:11:06
【问题描述】:
我有 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']);。
什么是正确的方法,以便我的应用将用户重定向到正确的路径?
【问题讨论】: