3

My Angular project folder structure is

+-- app.module.ts
+-- app-routing.ts
+-- app.component.ts
+-- product/
|   +-- product.module.ts
|   +-- product-routing.ts
|   +-- product-detail/
|   |   +--product-detail.component.ts
|   |   +--product-detail.component.html

In my app-routing.ts

{path:'products',loadChildren:'app/product/product.module#ProductModule'}

In my product-routing.ts

{ path: 'detail', component: ProductDetailComponent }

When I load the url - page/product/detail , I get the following error

ERROR Error: Uncaught (in promise): Error: Cannot find module "app/product/product.module". Error: Cannot find module "app/product/product.module".

Steps tried
tried changing 'app/product/product.module#ProductModule' to './product/product.module#ProductModule'. not solved.

Where I have went wrong? Any help is appreciated.

S.Pradeep
  • 487
  • 1
  • 5
  • 16

3 Answers3

1

That can be solved by removing your typo mistake. You declared Product Module & in routing you are calling Products Module (which is not). Change to:

{path: 'products', loadChildren: './product/product.module#ProductModule'}
Isurendrasingh
  • 432
  • 7
  • 20
1

You can try loadChildren for lazy module loading

I have create a demo on Stackblitz

{path:'products',loadChildren: './product/product.module#ProductsModule''}
Krishna Rathore
  • 9,389
  • 5
  • 24
  • 48
1

Try this approach, I used it for Angular 9

const routes: Routes = [
  {
    path: 'customers',
    loadChildren: () => import('./customers/customers.module').then(m => m.CustomersModule)
  },
  {
    path: 'orders',
    loadChildren: () => import('./orders/orders.module').then(m => m.OrdersModule)
  }
];
johannesMatevosyan
  • 1,974
  • 2
  • 30
  • 40