You can use an angular http-interceptor to intercept all your requests. When your token or session expires http responses will be 401(unauthorized). Based on that you can redirect user to the login route.
See the documentation for HttpInterceptor.
Something like this.
export class YourInterceptor implements HttpInterceptor {
constructor() {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).do((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
// do stuff with response if you want
}
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
// redirect to the login route
// or show a modal
}
}
});
}
}
Hope this helps.