我正在尝试执行以下操作
我可以使用router-outlet和app.routing-module.ts成功导航到侧面导航栏。我尝试对Nav4组件内的选项卡进行辅助布线。但是失败了。有人可以帮我吗?
app.routing-module.ts 导入所需的组件后
const routes: Routes = [
{ path: '', component: Nav1Component},
{ path: 'nav2', component: Nav2Component},
{ path: 'nav3', component: Nav3Component},
{
path: 'nav4', component: Nav4Component, children: [
{ path: 'tab1', component: Tab1Component, outlet: 'configureoutlet'},
{ path: 'tab2', component: Tab2Component, outlet: 'configureoutlet'}
{ path: 'tab3', component: Tab3Component, outlet: 'configureoutlet'},
{ path: 'tab4', component: Tab4Component, outlet: 'configureoutlet'},
{ path: 'tab5', component: Tab5Component, outlet: 'configureoutlet'},
]
}
];
app.component.html
<router-outlet></router-outlet>
Nav4component.html
<h4>Nav 4 general content</h4>
<ul>
<li routerlink="['/nav4', { outlets: { configureoutlet: ['tab1'] }} ]" routerLinkActive='active'>Tab 1</li>
<li routerlink="['/nav4', { outlets: { configureoutlet: ['tab2'] }} ]" routerLinkActive='active'>Tab 2</li>
<li routerlink="['/nav4', { outlets: { configureoutlet: ['tab3'] }} ]" routerLinkActive='active'>Tab 3</li>
<li routerlink="['/nav4', { outlets: { configureoutlet: ['tab4'] }} ]" routerLinkActive='active'>Tab 4</li>
<li routerlink="['/nav4', { outlets: { configureoutlet: ['tab5'] }} ]" routerLinkActive='active'>Tab 5</li>
</ul>
<router-outlet name='configureoutlet'></router-outlet>
运行应用程序时出现以下错误:
错误:无法匹配任何路线
答案 0 :(得分:1)
您可以指定相对路径,诸如此类
<li routerlink="['tab1']" routerLinkActive='active'>Tab 1</li>
<li routerlink="['tab2']" routerLinkActive='active'>Tab 2</li>
<li routerlink="['tab3']" routerLinkActive='active'>Tab 3</li>
<li routerlink="['tab4']" routerLinkActive='active'>Tab 4</li>
<li routerlink="['tab5']" routerLinkActive='active'>Tab 5</li>
路由器出口将很简单,
<router-outlet></router-outlet>