我有一个身份验证拦截器,但是,我希望这个拦截器过滤请求,而不是在用户访问不需要用户身份验证的确认帐户密码等组件时应用。关于如何去做的任何例子?这是身份验证拦截器的逻辑:
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Get the auth token from the service.
let authToken = this.authService.getToken();
let authHeader = 'Bearer ' + authToken;
//For requests that are retried, we always want a fresh copy, else the request will have headers added multiple times.
//So Clone the request before adding the new header.
//NOTE: the cache and pragma are required for IE that will otherwise cache all get 200 requests.
const authReq = request.clone({
setHeaders: {
Authorization: authHeader,
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
}
});
// Pass on the cloned request instead of the original request.
return next.handle(authReq);
}