angular: [GuardChecks] Cannot read _routeConfig of null

From @francois-appliware on June 14, 2016 13:47

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.

Copied from original issue: angular/vladivostok#48

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 26 (22 by maintainers)

Most upvoted comments

@sfabriece the fix landed with alpha 8, which is already live, see the changelog for the router https://github.com/angular/angular/blob/master/modules/%40angular/router/CHANGELOG.md.

Thanks @ericmartinezr. It’s hard to keep up with all the changelogs. Bookmarked!

From @sky-coding on June 19, 2016 5:22

This bug is still present and is blocking our development using the new router. This is very frustrating given that the blog says to use 3.0 immediately, and documentation has been removed