我正在尝试使用带模块的路线......
app.module
{
path: '',
component: AppComponent,
children: [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', loadChildren: 'app/dashboard/dashboard.module#DashboardModule'
]
}
使用导入RouterModule.forRoot(appRoutes)
dashboard.module
{
path: '',
component: DashboardComponent,
children: [
{ path: '', redirectTo: 'conta', pathMatch: 'full' },
{ path: 'conta', loadChildren: 'app/dashboard/conta/conta.module#ContaModule' }
]
}
使用导入RouterModule.forChild(dashboardRoutes)
conta.module
{
path: '',
component: ContaComponent,
children: [
{ path: '', redirectTo: 'list', pathMatch: 'full' },
{ path: 'list', component: ContaListComponent }
]
}
使用导入RouterModule.forChild(contaRoutes)
这个想法是:
当我运行此代码时,应用正在加载应用> Conta> ContaList 而非 App>仪表板> Conta> ContaList 我的意愿。
我的模板(App,Dashboard和Conta)里面有一个路由器插座。
我做错了什么?
答案 0 :(得分:1)
在仪表板组件中,您需要将路径指定为仪表板,并在conta模块中指定相同的
{
path: 'dashboard',
component: DashboardComponent,
children: [
{ path: '', redirectTo: 'conta', pathMatch: 'full' },
{ path: 'conta', loadChildren: 'app/dashboard/conta/conta.module#ContaModule' }
]
}
{
path: 'conta',
component: ContaComponent,
children: [
{ path: '', redirectTo: 'list', pathMatch: 'full' },
{ path: 'list', component: ContaListComponent }
]
}