3
votes

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.

3
restart ng serve - Sachila Ranawaka
'product' or 'products'? Subfolder includes 's' at the end and all configs/routings as well? - MarkusEgle

3 Answers

1
votes

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'}
1
votes

You can try loadChildren for lazy module loading

I have create a demo on Stackblitz

{path:'products',loadChildren: './product/product.module#ProductsModule''}
0
votes

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)
  }
];