延迟加载模块不加载模块js文件

时间:2017-06-27 10:47:21

标签: angular angular2-routing systemjs

我有两个模块,我正在加载延迟加载这些模块。

  1. 的AppModule
  2. PassangerModule
  3. AppModule定义如下

    @NgModule({
        imports: [
            BrowserModule,
            FormsModule,
            HttpModule,
            CabModule,
            RouterModule.forRoot([
                { path: '', component: CabComponent },
                { path: 'Cabs', component: CabComponent },
                { path: 'Passanger', loadChildren: 'App/Passanger/passanger.module#PassangerModule' }
            ])
        ],
        declarations: [
            AppComponent,
            CabComponent,
            CabFilterPipe,
            CabAddComponent
        ],
        bootstrap: [AppComponent],
        providers: [
            CabService
        ]
    })
    export class AppModule { }
    

    和ProductModule定义如下:

    @NgModule({
        imports: [
            CommonModule,
            RouterModule.forChild([
                {
                    path: '', component: PassangerComponent
                }
            ])
        ],
        declarations: [
            PassangerComponent
        ],
        providers: [
            PassangerService
        ]
    })
    export class PassangerModule {
    }
    

    现在,当我导航到/ Products时,它无法正常运行并尝试在http://localhost:3000/App/Passanger/passanger.module上获取GET请求,而这是非有效路径,而是应该在passanger.module.js上应用GET

    我加倍检查它在systemjs.config.js中将defaultExtension作为js

1 个答案:

答案 0 :(得分:1)

我更改了路径模块路径并将App/...设置为小写app/...并且它有效。

我不知道为什么该字符串区分大小写,但它对我有用。

RouterModule.forRoot([
            { path: '', component: CabComponent },
            { path: 'Cabs', component: CabComponent },
            { path: 'Passanger', loadChildren: 'app/Passanger/passanger.module#PassangerModule' }
        ])
相关问题