【问题标题】:Route between components under the same lazy module without activating the canActivateChild同一个lazy模块下的组件间路由,不激活canActivateChild
【发布时间】:2022-10-26 03:22:00
【问题描述】:

我有一个名为 FirstComponent 的组件,它的位置在 /hub/first 中。 hub-routing 模块检查每条路由,如下所示:

const routes: Routes = [
  {
    path: '',
    canActivateChild: [HubGuard],
    children: [
      {
        path: 'firstComponent,

这意味着 HubGurad CanActivate 函数将检查每个“/hub”路由。

我还有一个用于检查和条件的第一个组件路由的保护,如果它不存在,它会将它重定向到'/hub/secondComponent'。

我面临的问题是我可以看到,虽然我在同一个 HubModule 下的 2 个组件内路由,但再次调用了“canActivate”函数。有没有一种方法可以在不重新激活 CanActivateChild 保护的情况下从第一个组件路由到第二个组件?

【问题讨论】:

    标签: angular angular-routing canactivatechild


    【解决方案1】:

    你应该只使用canActivate 而不是canActivateChild 守卫。一旦你进入它就会检查这个路由分支。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多