【问题标题】:keeping default route with parent route in angular以角度保持默认路由与父路由
【发布时间】:2018-04-22 11:38:57
【问题描述】:

我有名为“个人资料”的父路由,在里面我有子路由,如基本、公司、联系人。所以当我点击像 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
            }
        ]
    }

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

【问题讨论】:

    标签: angular angular-routing


    【解决方案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
            }
        ]
    }
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-06-13
        • 1970-01-01
        • 2015-12-09
        • 2019-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多