gpt4 book ai didi

angular - 保持默认路由与父路由的 Angular

转载 作者:行者123 更新时间:2023-12-04 17:48:17 25 4
gpt4 key购买 nike

我有一个名为“Profile”的父路由,在里面我有一些子路由,比如 basic、company、contacts。因此,当我单击像 Profile 这样的父路由时,默认情况下它应该显示基本组件中存在的内容。

export const appRoutes: Routes = [
{ path: 'profile', component: ProfileComponent,
children: [
{
path: 'basic',
component: BasicComponent,
pathMatch: 'full'
},
{
path: 'company',
component: CompnayComponent
},
{
path: 'contacts',
component: ContactsComponent
},
{
path: 'compliance',
component: ComplianceComponent
}
]
}

因此,当用户点击个人资料时,基本内容应该会自动显示。那么如何实现呢?谁能帮帮我?

最佳答案

在你的路由配置中添加重定向到 basic:

 export const appRoutes: Routes = [
{ path: 'profile', component: ProfileComponent,
children: [
{
path:'',
redirectTo: 'basic',
pathMatch: 'full'
},
{
path: 'basic',
component: BasicComponent,
pathMatch: 'full'
},
{
path: 'company',
component: CompnayComponent
},
{
path: 'contacts',
component: ContactsComponent
},
{
path: 'compliance',
component: ComplianceComponent
}
]
}

关于angular - 保持默认路由与父路由的 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47202496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com