我希望我的主页显示侧边栏菜单中的预选选项。我该怎么办?就像我想要有人登陆主页一样,他应该出现在主页>侧边栏>关于
const appRoutes: Routes = [
{
path: '', component: HomeComponent, children: [{
path: 'sidebar', component: SidebarComponent, children: [
{ path: 'about', component: AboutComponent },
{ path: 'clients', component: ClientsComponent },
{ path: 'services', component: ServicesComponent },
{ path: 'contact', component: ContactComponent },
{ path: 'datatable', component: DataComponent }
]
}]
}
答案 0 :(得分:0)
您可以使用空路径和 redirectTo 属性来实现您的目标。
const appRoutes: Routes = [
{
path: '', component: HomeComponent, children: [
{ path: '', redirectTo: '/sidebar', pathMatch: 'full' },
{
path: 'sidebar', component: SidebarComponent, children: [
{ path: '', redirectTo: '/about', pathMatch: 'full' },
{ path: 'about', component: AboutComponent },
{ path: 'clients', component: ClientsComponent },
{ path: 'services', component: ServicesComponent },
{ path: 'contact', component: ContactComponent },
{ path: 'datatable', component: DataComponent }
]
}]
}
您可以参考redirecting routes和child route configuration的Angular文档。