Angular-在解析器的catchError()中使用skipLocationChange

时间:2019-03-14 11:38:01

标签: angular error-handling angular-router

不良行为:

导航到/article/123,如果文章不存在,则ArticleResolver处理错误并导航到ErrorComponent this.router.navigate(['error'], { skipLocationChange: true }),并保留/article/123网址。

发生了什么事

/article/123未保留。相反,我得到的是以前的网址。似乎网址/article/123从未被推送到路由器历史记录。

我的代码:

resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<any> {

    return this.articleService.get(route.params['id'])
      .pipe(catchError((err) => {

        if (err.StatusCode === 500) {
          this.router.navigate(['error'], { skipLocationChange: true });
          return of(false);
        }

        return of(null);
      }
    ));
  }

0 个答案:

没有答案
相关问题