lji*_*yao 9 router routes lazy-loading angular
我有我的app-routing.module.ts如下:
从'@angular/core' 导入 { NgModule };
进口 {
路线,
路由器模块
来自'@angular/router';
const 路由:路由 = [
{
路径:'重置',
loadChildren: 'app/auth/reset-password-form/reset-password-form.module#ResetPasswordFormModule'
},
{
路径:'验证',
loadChildren: 'app/auth/verify-user-form/verify-user-form.module#VerifyUserFormModule'
},
{
路径:'404',
loadChildren: 'app/route-not-found/route-not-found.module#RouteNotFoundModule'
},
{
小路 : '',
路径匹配:'完整',
loadChildren: 'app/landing-page/landing-page.module#LandingPageModule'
},
{
小路 : '**',
重定向到:'/404'
},
];
@NgModule({
进口:[RouterModule.forRoot(routes)],
出口:[路由器模块]
})
导出类 AppRoutingModule {
}
当我浏览到的localhost:4200,它会加载landing-page.module正确的,但是,当我进入localhost:4200/reset或localhost:4200/verify或者localhost:4200/404,它不会加载相关模块,相反,它加载landing-page.module自动。
我怎么解决这个问题?
小智 1
您必须将路由添加到您的子模块
const routes: Routes = [
{ path: '', component: ResetComponent}
];
const ROUTES: ModuleWithProviders =
RouterModule.forChild(routes);
Run Code Online (Sandbox Code Playgroud)
并在子模块中导入ROUTES(ResetModule)
@NgModule({
imports: [
CommonModule,
ROUTES,
],
declarations: [ResetComponent],
exports: [ResetComponent]
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1619 次 |
| 最近记录: |