My Angular 项目文件夹结构为
+-- 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
在我的应用程序路由中
{path:'products',loadChildren:'app/product/product.module#ProductModule'}
在我的产品路由中
{ path: 'detail', component: ProductDetailComponent }
当我加载网址 - 页面/产品/详细信息时,出现以下错误
错误 错误:未捕获(在承诺中(:错误:找不到模块"应用程序/产品/产品.模块"。 错误:找不到模块"应用程序/产品/产品.模块"。
尝试的步骤尝试
将"应用程序/产品/产品.模块#产品模块"更改为 './product/product.module#ProductModule'.没有解决。
我哪里做错了?任何帮助,不胜感激。
您可以尝试loadChildren
延迟模块加载
我已经在堆栈闪电战上创建了一个演示
{path:'products',loadChildren: './product/product.module#ProductsModule''}
这可以通过删除您的错别字错误来解决。您声明了产品模块,并在路由中调用了产品模块(不是(。更改为:
{path: 'products', loadChildren: './product/product.module#ProductModule'}
试试这种方法,我把它用于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)
}
];