有没有办法在不复制children属性代码的情况下完成这种方法?
const routes: Routes = [
{
path: '', component: SmartSearchComponent, canActivate: [AuthGuard],
canActivateChild: [AuthGuard],
children: [
{path: '', redirectTo: 'home', pathMatch: 'full'},
{path: 'home', component: HomeComponent},
{
path: 'member-profile/:mcid',
component: MemberProfileComponent,
children: [
{path: '', redirectTo: 'member-info', pathMatch: 'full'},
{path: 'member-info', pathMatch: 'full', component: MemberInfoComponent},
{path: 'id-cards', component: IdCardsComponent},
{path: 'register-family-members', component: RegisteredFamilyMembersComponent},
{path: 'associate-caregivers', component: AssociateCaregiversComponent},
{path: 'member-preferences', component: MemberPreferencesComponent},
{path: 'two-fa-info', component: TwofaInfoComponent},
{path: 'coverage/:hcid', component: CoverageComponent},
]
},
{
path: 'member-profile/:mcid/:hcid',
component: MemberProfileComponent,
children: [
{path: '', redirectTo: 'member-info', pathMatch: 'full'},
{path: 'member-info', pathMatch: 'full', component: MemberInfoComponent},
{path: 'id-cards', component: IdCardsComponent},
{path: 'register-family-members', component: RegisteredFamilyMembersComponent},
{path: 'associate-caregivers', component: AssociateCaregiversComponent},
{path: 'member-preferences', component: MemberPreferencesComponent},
{path: 'two-fa-info', component: TwofaInfoComponent},
{path: 'coverage/:hcid', component: CoverageComponent},
]
}
]
}
];
我有一个路线代码重复member-profile/:mcid,member-profile/:mcid/:hcid我不太喜欢。我试图拥有一个可以创建这两个对象的函数,但 Angular 抱怨我不能在模板中拥有方法。
如果我使用该路线,因为member-profile/:mcid/:hcid?它也不起作用。
有什么更好的方法吗?