1

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?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Olaf
  • 11
  • 1
  • 2

2 Answers2

0

I believe you can add the

canDeactivate: [CanDeactivateGuard]

inside your child routes definition instead of the parent route.

billias
  • 775
  • 7
  • 17
  • the thing is I would like to have a guard protecting from navigating outside of child routes not guard for each of them. – Olaf Aug 28 '16 at 18:35
0

It was a bug, it works as expected now.

Olaf
  • 11
  • 1
  • 2