简体   繁体   English

Angular App-Routing LoadChildren 找不到模块

[英]Angular App-Routing LoadChildren Can't find module

I am new to Angular and following a video tutorial.我是 Angular 的新手,并遵循视频教程。 I am stuck on the App-Rounting where it is trying to load child components.我被困在试图加载子组件的 App-Rounting 上。 Here is the code so far这是到目前为止的代码

app-routing.module.ts

import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { RouterModule, Routes } from "@angular/router";

import { HomeComponent } from "./home/home.component";

const appRoutes: Routes = [
  { path: "", component: HomeComponent },
  {
    path: "customers",
    loadChildren: "../app/customers/customers.module#CustomersModule"
  }
];

@NgModule({
  imports: [CommonModule, RouterModule.forRoot(appRoutes)], // add the routes to import array
  exports: [RouterModule], // after import, export the RouterModule after adding appRoutes
  declarations: []
})
export class AppRoutingModule {} 

I tried change the loadChildren: "../app/customers/customers.module#CustomersModule" to loadChildren: "app/customers/customers.module#CustomersModule"我尝试将 loadChildren: "../app/customers/customers.module#CustomersModule" 更改为 loadChildren: "app/customers/customers.module#CustomersModule"

The file tree structure is the following文件树结构如下

src\
  app\
    app-routing.module.ts
    customers\
      customers.module.ts
      customers.module.spec.ts

I am not sure why it can't find and load the customers.module.ts.我不确定为什么它找不到并加载customers.module.ts。 At first, I didn't have the customers.moudle.spec.ts and added it but it still throw the same error on the chrome console.起初,我没有 customers.moudle.spec.ts 并添加了它,但它仍然在 chrome 控制台上抛出相同的错误。

node version is v14.16.0 node version is 6.14.11节点版本为 v14.16.0 节点版本为 6.14.11

Any help is appreciated for this newbie.对此新手的任何帮助表示赞赏。

Thanks谢谢

I think your tutorial is old,you must use new syntax我认为您的教程很旧,您必须使用新语法

const routes: Routes = [
  {
    path: 'items',
    loadChildren: () => import('./items/items.module').then(m => m.ItemsModule)
  }
];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM