angular: Cannot read _routeConfig of null

This issue was posted by @francois-appliware under angular/vladivostok and was gaining traction until the repo was merged into this one. I’m posting it here for visibility.

Hi, I am working with the new router and had an issue that I “managed to resolve”, but as I don’t quite understand how everything works under the hood I prefer to open this issue and try to understand what is going on.

In my application, I have a few routes as following :

{ path: '/dashboard', component: DashboardComponent },
{
    path: '/companies', component: CompanyComponent, children: [
        { path: '/details/:id', component: CompanyDetailComponent },
        { path: '/new', component: CompanyEditComponent },
        { path: '/', component: CompanyDetailComponent, index: true }
    ]
},
{
    path: '/keys', component: KeyComponent, children: [
        { path: '/details/:id', component: KeyDetailComponent },
        { path: '/new', component: KeyEditComponent },
        { path: '/', component: CompanyDetailComponent, index: true }
    ]
}

When I am navigating from companies to keys, I have the following error :

Error {rejection: TypeError: Cannot read property '_routeConfig' of null
at GuardChecks.runCanDeactivate (http://l…, promise: ZoneAwarePromise, zone: Zone, task: ZoneTask, message: "Uncaught (in promise): TypeError: Cannot read property '_routeConfig' of null"}

So I went ahead and downloaded the code to see what was going on inside that “GuardChecks”.

For what I understand, it is used for the CanActivate / CanDeactivate (that I do not use in any of my components). Also, from what I understand, it is working with nullable values (in my case, where I don’t have such guards).

Problem is, at some point in adds a check with a null value that throws the previous error mentioned above.

I managed to solve my issue by replacing the following line inside “router.js” inside the method GuardChecks.prototype.runCanDeactivate = function (component, curr) var canDeactivate = curr._routeConfig ? curr._routeConfig.canDeactivate : null; by the following : var canDeactivate = curr ? (curr._routeConfig ? curr._routeConfig.canDeactivate : null) : null;

(Yes, it’s ugly but that’s a hotfix so I can continue working) I think the check can be set before the ‘runCanDeactivate’, where the checks are added, maybe in the traverseRoutes method inside GuardChecks.

Is this a known bug or a real bug and needs a fix or is it intended ?

Thank you.

This bug has been present in the 3.0.0 router since release and is still present in alpha-7. It makes the router unusable for production applications. Hopefully this can be resolved and released soon. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

As of now, this is still an issue. I’m using 2.0.0-rc.3 for all my angular packages except for the router package which is version 3.0.0-alpha.7. I believe the update to fix this issue was made after alpha.7 was released. Still waiting on alpha.8 to see if the fix works or not

Confirmed fixed in alpha.8. thank you @vsavkin

fwiw this is supposed to be fixed by https://github.com/angular/vladivostok/commit/9d6819b39e2b7952bc724c7531c4f53182af5e95 as mentioned here https://github.com/angular/vladivostok/pull/76#issuecomment-227022154

Sadly all the issues opened there dissapeared, all those with feature requests, bug reports, etc… they should have been moved here (unless I’m the only one that can’t see them in vladivostok’s repo)

any update on when we can expect an alpha.8 of the router? This issue is blocking our development

Excellent thanks to all parties involved

@ericmartinezr confirmed they disappeared. I looked for this issue here with no luck before before posting it. This is a blocking issue for us and I didn’t want it to lose visibility.