0
我檢查用戶的令牌登錄,如果認證失敗(返回401錯誤)我想重定向到登錄。我遇到的問題是,當我犯了錯誤趕上router.navigate不起作用。角2 HTTP抓路由器導航不工作
constructor(private http: Http , private router : Router)
authUser(){
return this.http.get(this.baseEndPoint+'/auth/user',Helpers.requestAuthOptions())
.map((response) => response.json())
.catch(this.handleError.bind(this));
}
public handleError = (error) => {
this.router.navigate(['/login']);
console.log('Hello!');//Hello appears in my console
return Observable.throw(error);
};
通常嘗試爲'.catch(this.handleError);' – SaiUnique
你這裏得到任何錯誤? –