我正在添加一个 Angular 8 路由解析器来预取数据。失败后(出于任何原因),我返回一个 EMPTY 以取消路线导航。但是,当我对此进行测试时,我可以进入 catchError 块,它显示烤面包机,并返回 EMPTY,但不会取消路线导航。根据我读过的所有文章,这应该有效。想知道是否有人看到我没有看到的东西。我只包含了 resolve 方法,因为所有其他配置都在工作。
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Country[]> | Observable<never> {
return this.countryService.getCountries().pipe(
mergeMap((countries) => {
if (countries)
{
return of(countries);
}
return EMPTY;
}),
catchError(error => {
this.toasterService.pop('error', '', 'There was a problem prefetching the data required to submit a request. If the problem persists, please notify the administrator.');
return EMPTY;
}));
}
我希望此代码根据角度文档取消导航。