当用户尝试访问未允许的页面时,我希望将其导航到错误页面。但问题是,在这种情况下,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);
});
}