Routing child to parent is not working when navigates in Angular

后端 未结 1 436
有刺的猬
有刺的猬 2021-02-06 05:51

I\'m using angular 5.1.0, and I have an issue with the routing system, let me explain:

In my app-routing module I have an url /api that lazy loads another m

相关标签:
1条回答
  • 2021-02-06 06:17

    I have solved the problem using NgZone, I think the "timing" routing problem that angular has involve the render error component out of angular zone, so, the AppErrorHandler class looks like this:

    import { ErrorHandler, Injectable, Injector, NgZone } from '@angular/core';
    import { Router } from '@angular/router';
    
    @Injectable()
    export class AppErrorHandler implements ErrorHandler {
    
      constructor(private injector: Injector) { }
    
      handleError(error: any): void {
        const routerService = this.injector.get(Router);
        const ngZone = this.injector.get(NgZone);
        ngZone.run(() => {
          routerService.navigate(['/error'], { skipLocationChange: true });
        });
      }
    }
    

    Here a github issue related to my problem

    0 讨论(0)
提交回复
热议问题