Is it possible to navigate to a specific route when a 401 error is catched, inside an HttpInterceptor?
What I've tried to do is:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
ā return next.handle(req)
.do((event: HttpEvent<any>) => {}, (error: any) => {
if (error instanceof HttpErrorResponse) {
if (error.status === 401) {
this.router.navigate(['/signin']);
}
}
});
ā}
But nothing is happening.
I can redirect to signin page only if using
window.location.href = '/signin';
instead of
this.router.navigate(['/signin']);