I want to redirect the user to a custom error page when a subscribe call to an observable throws an error. router.navigateByUrl('errorpage') I am getting the below error: ERROR Error: Uncaught (in promise): Error: Cannot activate an already activated outlet Error: Cannot activate an already activated outlet Thanks.
Try this
@ViewChild(RouterOutlet) outlet: RouterOutlet;
constructor(
private router: Router
) { }
ngOnInit(): void {
this.router.events.subscribe(e => {
if (e instanceof ActivationStart && e.snapshot.outlet === "errorpage")
this.outlet.deactivate();
});
}
Refrence:https://github.com/angular/angular/pull/20712
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With