Angular 2 route async resolve不会保持导航位置

izu*_*pet 15 javascript resolve typescript angular2-routing angular

尝试访问不允许的页面时,我尝试将用户导航到错误页面.问题是skipLocationChange在这种情况下不起作用.它导航到错误页面,但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);
    });
} 
Run Code Online (Sandbox Code Playgroud)

小智 0

问题是 this.route 是在根级别注入的,因此它将成为根路由。

您可以遍历路线来找到您感兴趣的路线。