调用window.location.href时,Angular HttpInterceptor无法正常工作

时间:2018-07-25 12:09:48

标签: angular angular-http-interceptors

调用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';

0 个答案:

没有答案