Angular2路由器登录时不导航
我不明白为什么路由器在成功登录后没有导航到请求的路由。控制台输出确实显示应该将用户发送到我单击的上一个URL,AuthGuard拒绝了该URL,但我的订阅中的router.navigate行似乎没有执行此导航Angular2路由器登录时不导航,angular,Angular,我不明白为什么路由器在成功登录后没有导航到请求的路由。控制台输出确实显示应该将用户发送到我单击的上一个URL,AuthGuard拒绝了该URL,但我的订阅中的router.navigate行似乎没有执行此导航 onLogin() { if (this.formCredentials.valid) { this.isLoading = true; this.auth.login(this.formCredentials.value.username, this.fo
onLogin() {
if (this.formCredentials.valid) {
this.isLoading = true;
this.auth.login(this.formCredentials.value.username, this.formCredentials.value.password)
.subscribe(
data => {
localStorage.setItem('id_token', data.access_token);
localStorage.setItem('refresh_token', data.refresh_token);
this.auth.requireLoginSubject.next(false);
console.log(this.auth.lastUrl);
this.router.navigate([this.auth.lastUrl]);
},
error => {
console.log(error);
var err = error.json();
localStorage.removeItem('auth_error');
localStorage.setItem('auth_error', JSON.stringify(err));
this.router.navigate(['/unauthorized']);
this.isLoading = false;
},
() => {
this.isLoading = false;
}
);
}
}
这似乎是一个已知的问题:
这似乎是一个已知的问题:
this.auth.lastUrl是否包含相对于导航的有效路由?(即不是完整的url…)this.auth.lastUrl的console.log输出是什么?实际上,一位同事刚刚向我指出了这个问题:@Bean0341控制台输出是:/audiences@Bean0341似乎是在混合使用AuthGuard时,问题才开始出现。pull请求将问题总结为:描述:guard取消了初始导航,返回false,但Router.navigated仍设置为true。路由器初始化为url等于/,因此当第二次导航发生时(this.Router.navigate(['/')),路由器会比较/和/,并取消导航,因为不允许再次导航到同一url。我认为只有在第一次成功导航后,我们才应该将Router.navigated设置为true。this.auth.lastUrl是否包含相对于导航的有效路由?(即不是完整的url…)this.auth.lastUrl的console.log输出是什么?实际上,一位同事刚刚向我指出了这个问题:@Bean0341控制台输出是:/audiences@Bean0341似乎是在混合使用AuthGuard时,问题才开始出现。pull请求将问题总结为:描述:guard取消了初始导航,返回false,但Router.navigated仍设置为true。路由器初始化为url等于/,因此当第二次导航发生时(this.Router.navigate(['/')),路由器会比较/和/,并取消导航,因为不允许再次导航到同一url。我认为我们应该在第一次成功导航后才将Router.navigated设置为true。