I am looking for a way to terminate an async route resolve.
The scenario is the user clicks a link that fetches data necessary for a component, and while that is resolving the user hits back, or clicks on another link. I would then want to cancel the current resolve and begin the new routing.
I can't intercept the routing by listening for these changes as no route event subscription fires while the existing route (still in the resolve phase) is processing.
For example my router may look like:
const appRoutes: Routes = [
{
path: 'resolvableRoute',
component: ResolvableRouteComponent,
resolve: {
data: RouteResolver
}
}];
And the resolver:
@Injectable()
export class RouteResolver implements Resolve<any> {
constructor(private http: HttpClient) {}
public resolve(router: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return this.http.get('api/path/for/data');
}
}
Until that http call returns in any way, the router is more or less stuck.
I have a nice loader that starts up while the route is transitioning, and I don't want to display the new component until I have the data necessary for that component, but I need to be able to terminate the request.
For example if I did not use the resolver, the user can navigate away from a component while that component is fetching data (on init for example) as I can then just destruct the component and terminate the http request. The downside to doing the component this way is I either have to show a blank page, or an incomplete page while I am in the processing of fetching data.