resolve method in the example on the angular.io returns a promise or navigates the application to the specific route if no data was found.
resolve(route: ActivatedRouteSnapshot): Promise<any> {
let id = +route.params['id'];
return this.cs.getCrisis(id).then(crisis => {
if (crisis) {
return crisis;
} else { // id not found
this.router.navigate(['/crisis-center']);
return false;
}
});
}
suppose, that getCrisis function returning an observable:
resolve(route: ActivatedRouteSnapshot): Observable<any> {
let id = +route.params['id'];
return this.cs.getCrisis(id).take(1)
}
in case of observable. How do i know, that nothing is returned, as i am dealing with stream? what would be the best pattern to handle this case inside the resolve function?
I know, that i could user router.navigate method from the component, but would like to use the router resolve guard properly.