I have a simple resolver for a route like /orders/first:
resolve(): Promise<Order> {
return this.orderService.get()
.then((response) => response.order)
.catch(error => Promise.reject(error));
}
I also have an error handler that redirects to an error page:
this.router.navigate(['/error'], { skipLocationChange: true });
I want the URL to be /orders/first so if the user refresh he might be able to view the page. This also make back button return to an incorrect page (previous previous page)
The problem is that the resolver runs before route activation so the URL doesn't change.
Is there a way to do this?
EDIT: Found this workaround:
- Listen to router event
NavigationStartand save route to a variable - Set location URL before redirecting to error page:
this.location.go(nextRoute.url); - Redirect with
skipLocationChangeset to true