【问题标题】:nested routing angular 6 doesn't fire嵌套路由角度 6 不会触发
【发布时间】:2020-04-28 21:20:45
【问题描述】:

大家好,我有一个带有组件的模块,我想在其中一个组件中添加组件,因为我有管理员,这个模块有子页面,它的路由是

const routes: Routes = [
  {
    path: '',
    component: AdminComponent,
    children: [
      { path : 'Dashboard' , component: DashboardComponent},
      // { path: 'User', component: UserComponent },
      { path: 'User', loadChildren: './user/user.module#UserModule'},
      { path: '', redirectTo: 'Dashboard', pathMatch: 'full' },
    ],
  },
  { path: '**', component: SystemErrorComponent }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class AdminRoutingModule { }

在用户下,我添加了像 add 和 details 之类的多组件,并且我为它设置了路由

const routes: Routes = [

  {
    path: '',
    component: UserComponent,
    children: [
      { path: 'userlist', component: UserlistComponent },
      { path : 'adduser' , component: AdduserComponent},
      { path: ':id/Userdetails', component: UserdetailsComponent },
      { path: '', redirectTo: 'userlist', pathMatch: 'full' },
    ],
  }

];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class UserRoutingModule { }

我还添加了管理 HTML 和用户 HTML 当我单击用户链接时,我收到错误错误:组件用户组件不是任何 NgModule 的一部分,或者该模块尚未导入您的模块。 并没有打开我的路由中的错误是什么?

【问题讨论】:

    标签: angular typescript angular-routing


    【解决方案1】:

    错误只是说明 UserComponent 不可用于加载。

    所以首先检查UserComponent是否在UserModule的declarations数组中。

    如果这没有帮助,那么您可能需要发布 AdminModule 和 UserModule 源代码。

    【讨论】:

      【解决方案2】:

      我已将所有组件添加到声明中并从管理员中删除用户的用户声明然后它可以工作

      【讨论】:

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