可以在HTTPInterceptor中通过Router服务来路由到错误页面。具体实现步骤如下:
import { RouterModule, Routes } from '@angular/router';
@NgModule({ imports: [RouterModule.forRoot(routes)], ... })
const routes: Routes = [ { path: 'error', component: ErrorComponent } ];
import { Router } from '@angular/router'; ... constructor(private router: Router) {}
intercept(req: HttpRequest
以上就是在Angular中通过HTTPInterceptor路由到错误页面的完整实现步骤。