Angular 4.X:初始化子组件路由器

时间:2017-08-25 09:52:34

标签: angularjs angular-ui-router

我有以下应用程序路由配置:

const routes: Routes = [
    {loadChildren: './modules/faq/faq.module', path: 'faq'},
    {loadChildren: './modules/pagination/pagination.module', path: 'page'},
    {loadChildren: './modules/appointmentAgreement/appointmentAgreement.module#AppointmentAgreementModule', path: 'terminvereinbarung'}
];

并且约会协议子模块路由配置

const appointmentAgreementRoutes: Routes = [{
    path: '',
    children: [
        {path: 'thema', component: TopicSectionComponent},
        {path: 'filiale', component: BranchSectionComponent},
        {path: 'termin', component: DatetimeSectionComponent},
        {path: 'daten', component: PersonalDataSectionComponent},
        {path: 'bestaetigung', component: ConfirmationSectionComponent},
    ]
}];

现在我希望应用程序重定向到/ terminvereinbarung / thema如果page / terminvereinbarung是开放的。

我怎样才能实现这个目标?

非常感谢adcance。

2 个答案:

答案 0 :(得分:1)

尝试在appointmentAgreement组件中执行以下操作:

const appointmentAgreementRoutes: Routes = [{
{
  path: 'terminvereinbarung',
  redirectTo: 'thema',
  pathMatch: 'full'
},
{
  path: 'terminvereinbarung',
  component: TopicSectionComponent,
}
children: [
    {path: 'thema', component: TopicSectionComponent},
    {path: 'filiale', component: BranchSectionComponent},
    {path: 'termin', component: DatetimeSectionComponent},
    {path: 'daten', component: PersonalDataSectionComponent},
    {path: 'bestaetigung', component: ConfirmationSectionComponent},
]

}];

答案 1 :(得分:1)

保留所有路由,因为它只是尝试在子模块

中的子项中添加此重定向
const appointmentAgreementRoutes: Routes = [{
path: '',
children: [
    { path: '', redirectTo: 'thema', pathMatch: 'full' },
    {path: 'thema', component: TopicSectionComponent},
    {path: 'filiale', component: BranchSectionComponent},
    {path: 'termin', component: DatetimeSectionComponent},
    {path: 'daten', component: PersonalDataSectionComponent},
    {path: 'bestaetigung', component: ConfirmationSectionComponent},
 ]
}];