如果搜索结果只有一个项目(如果reportId
= 1),我想导航到不同的页面,用户可以保存一次点击。这是我的解析器代码。
export class SearchResultsResolver implements Resolve<Report[]> {
constructor(private searchService: SearchService, private router: Router) {}
resolve(route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<Report[]> {
let reportId = route.params['reportId'];
return this.searchService.getReports(reportId);
console.log('reportid', reportId);
}
}
答案 0 :(得分:0)
您只需使用flatMap
,Observer.if
和router.navigate
的组合即可完成,如下面的代码段所示
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Array<Report>> {
let reportId = route.params['reportId'];
return this.searchService.getReports(reportId)
.flatMap(reports => Observable.if(() => reports && reports.length > 1,
Observable.of(reports),
this._router.navigate(['/otherRoute']))
);