我有一个中等大小的角度应用程序。这在装载时需要花费很多时间。因此我决定使用Lazy Loading。我有一个懒惰的FeedbackModule
。它看起来像这样:
反馈路线:
export const FEEDBACK_ROUTES: Routes = [
{ path : '' , component : FeedbackComponent},
{ path : 'prebilling' , component : PrebillingComponent},
{ path : 'postbilling/login' , component : PostbillingComponentLogin},
{ path : 'postbilling/rating/:mid/:return/:mtid' , component : PostbillingRatingComponent},
{ path : 'prebilling/rating/:mid/:type/:mtid/:mcnt/:mebid' , component : PrebillingRatingComponent},
{ path : 'prebilling/rating' , component : PrebillingRatingComponent},
{ path : 'postbilling/rating/:id' , component : PostbillingRatingComponent},
{ path : 'prebilling/rating/:mid/:type/:mtid' , component : PrebillingRatingComponent},
{ path : 'thanks/:id' , component : ThankYouComponent}
];
反馈模块:
@NgModule({
declarations: [
PostbillingComponentLogin,
PrebillingComponent,
PrebillingRatingComponent,
PostbillingRatingComponent,
ThankYouComponent,
FeedbackComponent,
PostbillingForgotPassComponentLogin
],
imports: [
CommonModule,
CommonCustomModule,
FormsModule,
RouterModule.forChild(FEEDBACK_ROUTES)
],
exports:[ RouterModule]
})
export class FeedbackModule {
}
App.route.ts:
export const ROUTES : Routes = [
...COMMON_ROUTES,
{ path:'feedback', loadChildren: './feedBack/feedback.module#FeedbackModule'}
]
现在,当我得到路径/feedback
反馈组件被加载。但是当我为/feedback/prebilling
或任何其他路径时它仍然加载FeedbackComponent。提前致谢 !
您的代码似乎对我不错,但您可以尝试添加pathMatch:full
{ path : '' , component : FeedbackComponent, pathMatch: 'full' }
请让我知道这对你有没有用...