调用window.location.href时,Angular HttpInterceptor不起作用
已在拦截器方法中添加了console.log(request),但没有被调用。
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let req = request.clone({
setHeaders: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
}
});
console.log('request is ' + JSON.stringify(req));
return next.handle(req);}
Called below code from a component
window.location.href = 'http://some-ip:some-port/some-path';