How Can I redirect to another page if the resolve fails in Angular 2? I call this resolve for my Edit Page, but I want to handle the errors in the Resolve Page
My Resolve:
resolve(route: ActivatedRouteSnapshot): Promise<any>|boolean { return new Promise((resolve, reject) => { if (route.params['id'] !== undefined) { this.dataService.getHttpEmpresaShow(this.endpoint_url_Get + route.params['id']) .subscribe( result => { console.log("ok"); return resolve(result); }, error => { return resolve(error); }); }});
Just like in the docs, calling this.router.navigate(["url"])
... (think to inject Router
in your constructor)
class MyResolve { constructor(private router: Router) {} resolve(route: ActivatedRouteSnapshot): Observable <any> { return this.dataService.getHttpEmpresaShow(this.endpoint_url_Get + route.params['id']) .pipe(catchError(err => { this.router.navigate(["/404"]); return EMPTY; })); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With