角卫士导航到父路线

时间:2018-09-26 20:38:26

标签: angular angular-ui-router

我有一个具有以下路由的应用程序:

  • / root / foo
  • / root / bar
  • / root / foo /(出口:X)
  • / root / bar /(出口:X)

导航到/root/foo/root/bar将计算值X并分别重定向到/root/foo/(outlet:X)/root/bar/(outlet:X)

是否有一种实现Guard的方法,可以防止单击从/root/foo/root/foo/(outlet:X)的路由器链接?

2 个答案:

答案 0 :(得分:0)

您可以实施canDeactivate保护,检查当前和目标网址,并在特定情况下阻止导航。

答案 1 :(得分:0)

我设法通过使用CanDeactivate保护器使其起作用,但是在子组件上。

路线示例: { path: 'root/foo', component: ListComponent, children: [ { path: ':id', canDeactivate: [CanNavigateToParentRouteGuard], component: ChildComponent, outlet: 'outlet' } ] }, 守护: canDeactivate(component: ChildComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): boolean { return !currentState.url.startsWith(nextState.url); }

相关问题