角路线,子路由和默认路由
问题描述:
我试图使用路由与模块...角路线,子路由和默认路由
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
- 默认为CONTA路线contaList
当我运行这段代码,应用程序加载应用> CONTA> ContaList,而不是应用>控制面板> CONTA> ContaList我多么希望。
我在我的模板(应用程序,仪表板和Conta)里面有一个路由器插座。
我在做什么错?
答
在你需要指定路径仪表盘等,同时在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 }
]
}
我之前尝试这个仪表板组件,但我有一个错误 **错误错误:未捕获的(在承诺):错误:无法匹配任何路线。网址细分:'列表' 错误:无法匹配任何路线。网址细分:'列表'** –