How can I uphold an api request from being cancelled when the router change in angular 7?

682 views Asked by At

I have used a 'Service' and an 'Interceptor' to cancel all pending request when i switch between pages in angular. I have followed the steps in this tutorial for that. Now i need to uphold some api calls from being cancelled on a router change.

I have tried searching for an answer but ended up in getting ways to cancel the requests. Is there a way to uphold the request from being cancelled? I am using angular 7.

Thanks in advance:)

1

There are 1 answers

1
Greg Grundy On

At the point where the cancel service in added to your HttpRequest you could try adding a rule to exclude that specific url.

  Intercept<T>(req: HttpRequest<T>, next: HttpHandler): Observable<HttpEvent<T>> {
        // adding this line worked for me
        if(req.url.endsWith('my/special/path'))return next.handle(req);
  
       return next.handle(req).pipe(takeUntil(this.httpCancelService.onCancelPendingRequests()))
     }