保持默认路线与父路线的角度

时间:2017-11-09 13:00:11

标签: angular angular-routing

我有一个名为“Profile”的父路线,里面我有基本,公司,联系人等子路线。所以当我点击像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
            }
        ]
    }

因此,当用户点击Profile时,会自动显示基本内容。那么如何实现呢?任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

在路线配置中添加重定向到基本:

 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
        }
    ]
}

答案 1 :(得分:0)

在子路径中添加重定向到基本

{path: '', redirectTo: 'basic'}

如果您现在导航到/profile/,它会重定向到/profile/basic