Angular interceptor exclude specific urls

Update from Angular 12, use “context”, see this SO

I suggest that, in spite of check the request, you can use the header to add a “skip” property, if the header has the skip property, simple return the reqs

export class CustomInterceptor implements HttpInterceptor {
    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        if (req.headers.get("skip"))
           return next.handle(req);
      
        ....
    }
}

And you make all the calls you need “skip” the interceptor like

this.http.get(url, {headers:{skip:"true"});

Leave a Comment