gpt4 book ai didi

angular - 默认angular导航到子路由

转载 作者:行者123 更新时间:2023-12-04 01:35:46 28 4
gpt4 key购买 nike

我试图默认导航到子路由,所以这是我的路由:

const routes: Routes = [
{
path: '', --> /config
redirectTo: 'branding',
component: ConfigurationComponent,
children: [
{ path: 'branding', component: BrandingComponent },
{ path: 'channel-branding', component: ChannelBrandingComponent },
{ path: 'date-time', component: DateTimeSettingsComponent },
{ path: 'graph', component: GraphSettingsComponent },
{ path: 'grid', component: GridSettingsComponent },
{ path: 'labels', component: LabelSettingsComponent }
]
},
];

父路由是 /config 子路由是 /config/branding 等我想去 /config/branding如果有人导航到 /config,则为默认值。我尝试使用 redirectTo 但这似乎破坏了所有的东西。我怎样才能得到这种行为?

最佳答案

在你的 child 数组中添加重定向,就像这样

 children: [
{ path: '', redirectTo: 'branding' },
{ path: 'branding', component: BrandingComponent },
{ path: 'channel-branding', component: ChannelBrandingComponent },
{ path: 'date-time', component: DateTimeSettingsComponent },
{ path: 'graph', component: GraphSettingsComponent },
{ path: 'grid', component: GridSettingsComponent },
{ path: 'labels', component: LabelSettingsComponent }
]

谢谢。

关于angular - 默认angular导航到子路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59653020/

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