Hello I added a route navigation in my custom exception handler of Angular but I have the problem that when an error is triggered on the onInit of an Angular component it goes into an error loop:
Error: Cannot activate an already activated outlet
This is the code for my component:
import { ErrorHandler, Injectable, Injector } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
@Injectable()
export class ErrorService implements ErrorHandler {
constructor(
private injector: Injector
) { }
get router(): Router {
return this.injector.get(Router);
};
handleError(error: any): void {
console.error(error);
this.router.navigate(['error', { error: error }], { skipLocationChange: true});
}
}
And these my routes:
export const routes: Routes = [
{ path: '', redirectTo: 'browser', pathMatch: 'full' },
{ path: 'browser', loadChildren: './modules/browserui#BrowserUiModule' },
{ path: 'error', component: ErrorComponent, data: { title: 'Generic error' } },
{ path: '**', component: ErrorComponent, data: { title: '404 not found' } }
];
Any ideas? Thank you!