angular: At least one route resolver didn't emit any value and so page not loading all times

817 views Asked by At

I am facing an issue in my angular page that sometimes my page is not loading. I have enabled tracing in routes and observed that in NavigationCancel event, it throws an error reason:

enter image description here

My route resolver is given below

@Injectable()
export class MyResolver implements Resolve<any> {
  constructor(...) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    const newPath = doSomeStuff()
    this.router.navigateByUrl(newPath)
  }
}

I suspect because I am not returning any stuff and redirecting to new path, the resolver is not emitting any value and hence this issue occurs. Please also note that other resolvers are properly emitting and I dont see any issues in that. Any suggestions how to overcome from this issue? Happy to share if any further details required.

1

There are 1 answers

0
Viswa On

Actually, I found the solution today and I observed that there is no issue in my resolver given above. I confused on MyResolver behaviour that it is not emitting value. The problem is with other resolvers which is defined in my child route. Before calling my ui page, these resolvers also getting called and one of the resolver (MyChildResolver) is not emitting value when this redirection happens. so, my routes given below

{
    path: '',
    resolve: { payload: MyResolver },
    children: [
      {
        path: ':childOne',
        component: MyChildComponent,
        resolve: { payload: ChildResolver },
        children: [
          { path: '', redirectTo: 'FirstChildOfChild', pathMatch: 'full' },
          {
            path: 'FirstChildOfChild',
            component: MyChildOfChildComponent,
            resolve: { payload: ChildOfChildResolver },
          },
        ]
      }
    ]
}

I have added console.log in all resolvers and identified the logs not captured in route tracing. Once I addressed that issue, the application starts showing all the time.