在尝试访问不允许的页面时,我尝试将用户导航到错误页面。问题是 skipLocationChange 在这种情况下不起作用。它导航到错误页面,但 url 更改为根目录。如何保持用户提供的原始url?
resolve(route: ActivatedRouteSnapshot): Observable<any|boolean>|boolean {
return this.apiclientService.get('cars/' + route.params['id']).map(
response => {
if (response.data.user_id === this.authService.user().id) {
return response.data;
}
this.router.navigate(['/404'], { skipLocationChange: true });
return false;
}
).catch(error => {
this.router.navigate(['/404'], { skipLocationChange: true });
return Observable.of(false);
});
}
最佳答案
我认为 skipLocationChange
确实有效。问题是 Angular 没有导航到新路线,因为守卫失败了。如果您想捕获失败的 URL,请检查 route: ActivatedRouteSnapshot
参数。
关于javascript - Angular 2 路由异步解析不会保留导航位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41210011/