Angular 4延迟加载子组件未加载

问题描述 投票:1回答:2

我有一个中等大小的角度应用程序。这在装载时需要花费很多时间。因此我决定使用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。提前致谢 !

angular lazy-loading
2个回答
2
投票

您的代码似乎对我不错,但您可以尝试添加pathMatch:full

{ path : '' , component : FeedbackComponent, pathMatch: 'full' }

请让我知道这对你有没有用...


1
投票

这是因为您没有将其他路由作为延迟加载模块的子路由

const ROUTES:Routes = [{path:'',component:OrgComponent,children:[{path:'intro',loadChildren:'../+intro/intro.module#IntroModule'},{path:'recent', component:RecentComponent},]}]

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.