我正在添加 Angular 8 路由解析器来预取数据。如果失败(出于任何原因),我会返回 EMPTY 以取消路线导航。但是,当我对此进行测试时,我可以进入 catchError 块,它显示烤面包机,并返回 EMPTY,但路线导航并未被取消。根据我读过的所有文章,这应该有效。想知道是否有人看到我没有看到的东西。我只包含了解析方法,因为所有其他配置都有效。
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;
}));
}
Run Code Online (Sandbox Code Playgroud)
我希望这段代码能够根据角度文档取消导航。