【问题标题】:Reusable component not seen by children routes components子路由组件看不到的可重用组件
【发布时间】:2020-07-02 01:55:33
【问题描述】:

我有 2 条延迟加载的路由:

const routes: Routes = [
{
    path: '',
    redirectTo: 'login',
    pathMatch: 'full'
  },
  {
    path: 'login',
    loadChildren: () => import('./login/login.module').then(m => m.LoginModule)
  },
  {
    path: 'dashboard',
    loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
  }
];

仪表板路线有子路线。

const routes: Routes = [
  {
    path: '',
    component: DashboardComponent,
    children: [
      {
        path: '',
        component: HomeComponent
      },
      {
        path: 'usuarios',
        component: UsersComponent
      }
    ]
  }
]

我创建了一个工具栏可重用组件,我想在仪表板路由器插座上呈现它,但是当我导航到仪表板模块的子路由时,角度编译器说 app-toolbar 不是组件。

我已经在 Dashboard 模块上添加了组件并在 AppModule 上进行了尝试,但我得到了相同的结果。 我错过了什么吗?

【问题讨论】:

    标签: angular angular-routing angular9


    【解决方案1】:

    我相信这是 Angular 中延迟加载路由的常见问题。尽管像您一样以编程方式指定LoadChildren 很方便,但您必须改用字符串,例如

    loadChildren: './login/login.module#LoginModule',
    

    【讨论】:

    • 在新的 Angular 版本中,loadChildren: () => import(...).then(...) 是代码拆分的“正确”方式
    • 我知道。我创建了一个 Angular 版本 ^8 的应用程序,但由于延迟加载,它对我也不起作用,所以我不得不改用字符串。
    猜你喜欢
    • 2019-06-16
    • 1970-01-01
    • 2021-05-31
    • 2016-12-19
    • 2016-09-04
    • 2021-10-31
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多