【问题标题】:candeactivate with child routes not workingcandeactivate 与子路由不工作
【发布时间】:2018-12-06 04:39:48
【问题描述】:

我的路由如下:

{
  path: "home",
  children: [{
    path: "dashboard",
    children: [{
      path: "user",
      canDeactivate: [CanWeDeactivateThis]
    }]
  }]
}

路由中定义了组件,上面只是一个简单的快照。 当我添加时我将组件设为 null 可以在用户路径中停用,但如果我将它添加到仪表板路径中,它运行良好。 添加仪表板对我不起作用,因为我在仪表板上有多个孩子,如果用户也导航到他们,我需要显示确认。

不知道如何解决这个问题。

角度版本是6.1.0

我关注了this thread,但没有任何帮助。

有人可以帮忙吗?

顺便说一句,上面的路由定义是延迟加载的角度模块的一部分。

【问题讨论】:

  • getting component as null 是什么意思。您是否遇到任何错误.. 请提供一些错误详细信息
  • canDeactivate(component: CanComponentDeactivate) { 守卫方法中,我将第一个参数component 设为null 而不是实际组件。

标签: angular angular6 router auth-guard


【解决方案1】:
{
  path: "home",
  children: [{
    path: "dashboard",
    children: [{
      path: "user",
      component : "user",
      canDeactivate: [CanWeDeactivateThis]
    }]
  }]
}

您应该为孩子添加组件名称。如果您想对所有孩子应用 canDeactivate 方法,也可以尝试以下代码。

{
      path: "home",
      children: [{
        path: "dashboard",
        canDeactivate: [CanWeDeactivateThis],
        children: [{
          path: "user",
          component : "user"          
        }]
      }]
    }

If the feature module is loaded asynchronously, the CanLoad guard is checked before the module is loaded. If any guard returns false, pending guards that have not completed will be canceled, and the entire navigation is canceled. 所以检查你是否还有任何 CanLoad 保护。

【讨论】:

  • 正如我在问题中提到的,“路由中定义了组件,上面只是一个简单的快照。”并且我不能移动可以停用为仪表板级别,因为我还想监视仪表板子级的更改。
  • 我没有 canLoad 保护。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-15
  • 2015-08-13
  • 1970-01-01
  • 2016-09-06
相关资源
最近更新 更多