Ionic 4 /角路由:错误错误:未捕获(承诺):错误:在'./home/home.module'

时间:2018-11-03 14:46:29

标签: angular angular2-routing lazy-loading ionic4

我正在试验昨天发布的Ionic 4 Beta 15。

这是我的AppRoutingModule

const routes: Routes            =   [{ 
    path                        :   '', 
    loadChildren                :   './tabs/tabs.module#TabsPageModule'
    /*
}, { 
    path                        :   'event/:id', 
    loadChildren                :   './event/event.module#EventModule'
}, { 
    path                        :   'ngo/:id', 
    loadChildren                :   './ngo/ngo.module#NgoModule'
    */
}, { 
    path                        :   'volunteer/:id', 
    loadChildren                :   './volunteer/volunteer.module#VolunteerModule'

}];

@NgModule({
    imports: [RouterModule.forRoot(routes, { enableTracing: true })],
    exports: [RouterModule]
})
export class AppRoutingModule {}

如上面的代码所示,如​​果我注释掉EventNgoVolunteer这3条路径中的任意2条,则路由工作正常。

但是当我同时启用2条路径中的任何一条时,会出现以下错误:

Error: Cannot find 'NgoHomePageModule' in './home/home.module'
    at checkNotEmpty (core.js:5007)
    at core.js:4984
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:3820)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
    at zone.js:872
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:3811)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at checkNotEmpty (core.js:5007)

与NGO或每个ionic serve的志愿者一起随机发生

在我的VolunteerModule中路由

const routes = [{
    path                        :   'home',
    loadChildren                :   './home/home.module#VolunteerHomePageModule'
}, {
    path                        :   'event',
    loadChildren                :   './event/event.module#VolunteerEventPageModule'
}, {
    path                        :   'achievement',
    loadChildren                :   './achievement/achievement.module#VolunteerAchievementPageModule'
}, {
    path                        :   '',
    redirectTo                  :   'home'
}];

在我的NgoModule中路由

const routes = [{
    path                        :   'home',
    loadChildren                :   './home/home.module#NgoHomePageModule'
}, {
    path                        :   'upcoming',
    loadChildren                :   './upcoming /upcoming.module#NgoUpcomingPageModule'
}, {
    path                        :   'past',
    loadChildren                :   './past/past.module#NgoPastPageModule'
}, {
    path                        :   'volunteer',
    loadChildren                :   './volunteer/volunteer.module#NgoVolunteerPageModule'
}, {
    path                        :   '',
    redirectTo                  :   'home'
}];

我的文件夹结构:

▾ ngo/
  ▸ home/
  ▸ past/
  ▸ upcoming/
  ▸ volunteer/
    [  ]ngo.module.spec.ts
    [  ]ngo.module.ts
▸ tabs/
▾ volunteer/
  ▸ achievement/
  ▸ event/
  ▸ home/
    [  ]volunteer.module.spec.ts
    [  ]volunteer.module.ts
  [  ]app-routing.module.ts

更新1: 将回购上传到 https://gitlab.com/saiy2k/ionic.4-beta.15-routing-issue

我在做什么错?请帮忙。

2 个答案:

答案 0 :(得分:1)

遇到了同样的问题,但是我只是停止了ionic serve并重新执行了它。

答案 1 :(得分:0)

使其有效,但解决方案令人难以置信。

使用唯一名称重命名功能的子文件夹,如下所示:

▾ ngo/
  ▸ home/ --> nhome/
  ▸ past/ --> npast/
  ▸ upcoming/ --> nupcoming/
  ▸ volunteer/ --> nvolunteer/
    [  ]ngo.module.spec.ts
    [  ]ngo.module.ts
▸ tabs/
▾ volunteer/
  ▸ achievement/ --> vachievement/
  ▸ event/ --> vevent/
  ▸ home/ --> vhome/
    [  ]volunteer.module.spec.ts
    [  ]volunteer.module.ts
  [  ]app-routing.module.ts

此更改解决了该问题。但是我不明白为什么!有什么解释吗?

将相同内容推送到https://gitlab.com/saiy2k/ionic.4-beta.15-routing-issue/tree/fix