2017-08-25 85 views
1

我有以下应用路由配置:角4.X:初始化子组件路由器

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

而且appointmentAgreement子模块路由配置

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

现在我想应用重定向到/如果page/terminverebarbarung是开放的话

我该如何做到这一点?

非常感谢。

回答

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}, 
] 
}]; 
+0

真棒,这是做的伎俩。谢谢! – user3507003

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

}];

+0

非常感谢这个快速的答案。它看起来像你的代码段中有语法问题。你能给出正确的吗? – user3507003

+0

我已经更新了我的答案,并删除了围绕路径的大括号 –

+0

我尝试了您的更新解决方案,但不幸的是它可以解决问题。 致电/ terminvereinbarung无组件 致电/ terminvereinbarung/thema给出错误: 错误:无法匹配任何路由。 URL段:'terminvereinbarung/thema – user3507003