我正在尝试延迟加载模块并出现错误
ERROR Error: Uncaught (in promise): Error: Cannot find module './user/user.module'
UserModule
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { userRoutes } from './user.routes';
import { ProfileComponent } from './profile.component';
@NgModule({
imports: [CommonModule, RouterModule.forChild(userRoutes)],
declarations: [ProfileComponent],
providers: []
})
export class UserModule {}
在userRoutes
{ path: 'user', loadChildren: './user/user.module#UserModule' }
完整错误堆栈
core.js:6241 ERROR Error: Uncaught (in promise): Error: Cannot find module './user/user.module'
Error: Cannot find module './user/user.module'
at $_lazy_route_resource lazy namespace object:5
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Object.onInvoke (core.js:41667)
at ZoneDelegate.invoke (zone-evergreen.js:363)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:41645)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at resolvePromise (zone-evergreen.js:798)
at resolvePromise (zone-evergreen.js:750)
at zone-evergreen.js:860
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:41645)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at drainMicroTaskQueue (zone-evergreen.js:569)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:484)
at invokeTask (zone-evergreen.js:1621)
答案 0 :(得分:0)
加载模块的新方法是使用箭头功能
将以下路径添加到应用程序路由ts
{ path: 'user', loadChildren: ()=> import('./user/user.module').then(m => m.UserModule)}:
然后在您的延迟加载模块中,用户路由一个这样的添加
const routes: Routes = [
{
path: '',
component: UsersComponent
}
];
如果您以最新版本创建了角度应用,请使用上述方法进行操作。
答案 1 :(得分:0)
您是否仅在UserModule中使用UserModule? 您提到要在userRoutes中定义lazyloading部分。那是不对的。 请在app-routing.module.ts中定义 并且该路径应相对于app-routing.module.ts