Olaf
Olaf

Reputation: 11

Angular 2 router 3.0.0-rc.1 deactivate guard protecting group of routes

I would like to create a deactivate guard that is trigerred only when navigating outside of child routes.

In rc4 ("@angular/router": "3.0.0-beta.1") this code was working as described:

path: '',
  component: RootComponent,
  canDeactivate: [CanDeactivateGuard],
  children: [{
    path: '',
    component: XComponent,
  }, {
    path: 'somepath',
    component: YComponent
  }]
}

In this example navigating from XComponent to YComponent did not trigger deactivate guard, but for example navigating to "someNotChildComponent" did.

After updating to @angular/route 3.0.0-rc.1 guard is triggered for every path change. What is correct behavior? Are there better ways to handle this case?

Upvotes: 1

Views: 395

Answers (2)

Olaf
Olaf

Reputation: 11

It was a bug, it works as expected now.

Upvotes: 0

billias
billias

Reputation: 825

I believe you can add the

canDeactivate: [CanDeactivateGuard]

inside your child routes definition instead of the parent route.

Upvotes: 0

Related Questions