Angular 2 路由器 3.0.0-rc.1 停用路由守卫保护组

问题描述 投票:0回答:2

我想创建一个停用防护,仅在导航到子路线之外时才会触发。

在 rc4 (

"@angular/router": "3.0.0-beta.1"
) 中,此代码按描述工作:

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

在此示例中,从

XComponent
导航到
YComponent
不会触发停用防护,但例如导航到
"someNotChildComponent"
则会触发停用防护。

更新到

@angular/route 3.0.0-rc.1
后,每次路径更改都会触发防护。什么是正确的行为?有更好的方法来处理这种情况吗?

angular angular2-routing angular2-router3
2个回答
0
投票

我相信你可以添加

canDeactivate: [CanDeactivateGuard]

在子路由定义中而不是父路由中。


0
投票

这是一个错误,现在可以按预期工作了。

© www.soinside.com 2019 - 2024. All rights reserved.