我有ngtabcontent,因此它的内容应该是动态的,因此为PersonalComponent创建子路由,然后单击下一步,它应该导航到其子路由。
const routes: { path: '', redirectTo: 'tenant', pathMatch: '{ path: "personal", component: children: [
{ path: 'employer', component: AddemployerComponent, outlet: 'test'},
]
},
{ path: "applicant", component: AddapplicantComponent },
{ path: 'tenant', component: TenantappComponent },
{ path: 'animal', component: AddanimalComponent },
{ path: 'vehicle', component: AddvehiclesComponent },
{ path: 'background-info', component: BackgroundInfoComponent },
{ path: 'termsandconditions', component: TermsandconditionsComponent },
{ path: 'payment', component: PaymentComponent }
];
所以这是我的路由模块,最初我在其中显示我的个人组件,然后单击下一步,它应该导航具有出口名称的子路由雇主。
nextFn() {
if (this.router.url === '/personal') {
this.router.navigate(['employer', {outlets: 'test'}]);
this.shared.isSubmitPayment = true;
} else if (this.router.url === '/employer') {
this.router.navigate(['animal']);
} else if (this.router.url === '/animal') {
this.router.navigate(['vehicle']);
} else if (this.router.url === '/vehicle') {
this.router.navigate(['background-info']);
} else if (this.router.url === '/background-info') {
this.router.navigate(['termsandconditions']);
} else if (this.router.url === '/termsandconditions') {
this.router.navigate(['payment']);
}}
在组件文件中,我的路线是这样的。
<div class="row personal-info">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon"><i class="fa fa-check" aria-hidden="true"></i></div>
</div>
<p class="registration"><b>Registration Successful</b></p>
</div>
</div>
<app-tenant-header></app-tenant-header>
<div class="form-feilds">
<h6>Personal Information</h6>
<ngb-tabset>
<ngb-tab [id]="tab.id" *ngFor="let tab of tabs;let i = index;">
<ng-template ngbTabTitle>
{{tab.title}}{{applicantNumberArray[i - 1]}}
</ng-template>
<ng-template ngbTabContent>
<div *ngIf="!shared.isSubmitPayment">
<app-formfields [personalInfo]=personalInfo [tabIndex]=i [tabs]=tabs (addApplication)="addApplicantFn($event)" (deleteApplication)="deleteApplicantFn($event)"></app-formfields>
</div>
<div *ngIf="shared.isSubmitPayment">
<router-outlet></router-outlet>
</div>
</ng-template>
</ngb-tab>
</ngb-tabset>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 property-footer">
<app-footer></app-footer>
</div>
和我的html这样....
预先感谢
答案 0 :(得分:0)
child route
和named route
之间是有区别的。
子路线用于应在另一个模板中出现的路由。根据需要定义它们,并在路由配置中使用children
属性。子路由被路由到父组件模板中的路由器出口。
命名路由用于应作为其他模板的同级显示的路由,例如并排显示。它们是用带有名称定义的路由器出口指定的。
从您的示例猜测,您想要的是子路线,而不是命名的路线。因此,您应该从代码中删除outlet
属性。
在此处删除:
{ path: 'employer', component: AddemployerComponent, outlet: 'test'}
在这里:
['employer', {outlets: 'test'}]