最初,应用程序显示登录页面并导航到maincontent组件,现在我想从仪表板组件导航到应用程序详细信息组件,但是收到错误
Error: Component DashboardComponent is not part of any NgModule or the module has not been imported into your module.
在我的app.module.ts中,我导入了所有组件
下面是我在app.module.ts
中提到的路线const appRoutes: Routes=[
{ path:'', redirectTo:'/login',pathMatch:'full'},
{ path: 'login', component: LoginComponent},
{ path: 'maincontent', loadChildren:
'./maincontent/maincontent.module#MainContentModule'
}
];
下面的是MainContentModule
中提到的路线 export const ROUTES: Routes = [
{
path: 'maincontent',
component: MainContentComponent,
children: [
{ path: 'dashboard', component:DashboardComponent,
loadChildren: './dashboard/dashboard.module#DashboardModule' },
]
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(ROUTES)
],
declarations: [],
exports:[
RouterModule,
]
})
export class MainContentModule {}
在我的DasboardModule
中export const ROUTES: Routes = [
{
path:'dashboard', component:DashboardComponent,
children:[
{
path:'application',component:ApplicationDetailsComponent
}
]
}
]
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(ROUTES)
],
declarations: [ ],
exports:[
RouterModule,
]
})
export class DashboardModule { }
任何帮助将不胜感激
答案 0 :(得分:4)
在DashboardComponent
声明中添加MainContentModule
:
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(ROUTES)
],
declarations: [DashboardComponent ],
exports:[
RouterModule,
]
})