angular - 角度共享模块导致加载其他共享模块
问题描述
在我的 Angular 11 应用程序中,我使用了延迟加载路由功能和共享模块功能。如果我在两个不同的功能模块中导入相同的模块,那么我发现 Angular 下载了另一个中间 js 文件。下面是我的示例代码。
客户模块:
import { CustomersRoutingModule } from './customers-routing.module';
import { CustomersComponent } from './customers.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [CustomersComponent],
imports: [CommonModule, CustomersRoutingModule, FormsModule],
})
export class CustomersModule {}
订单模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OrdersRoutingModule } from './orders-routing.module';
import { OrdersComponent } from './orders.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [OrdersComponent],
imports: [CommonModule, OrdersRoutingModule, FormsModule],
})
export class OrdersModule {}
应用路由模块:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: '', redirectTo: '/customers', pathMatch: 'full' },
{
path: 'customers',
loadChildren: () =>
import('./customers/customers.module').then((m) => m.CustomersModule),
},
{
path: 'orders',
loadChildren: () =>
import('./orders/orders.module').then((m) => m.OrdersModule),
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
以下是浏览器网络选项卡屏幕截图。
它显示加载了一个名为 default~customers-customers-module~orders-orders-.module.js 的额外 js 文件。Github 链接https://github.com/mustafizur8888/angular-lazyloading 那么如何解决呢?谢谢。
解决方案
推荐阅读
- android-source - libsepol.check_assertions: 2 neverallow failures occurred 扩展策略时出错
- java - 添加“包”时出现“错误:无法找到或加载主类示例”
- python - “ProgbarLogger”对象没有属性“log_values”
- ios - Alamofire 5 - file download execution time (Swift 5)
- react-native - 如何为已经存在的 React Native 应用程序构建架构
- python - 为什么在解析字典时出现 IndexError: list index out of range?
- graphql - 如何在 graphql-js 中为对象类型定义解析器?
- transaction-isolation - 由于同时选择而重试插入的事务
- autodesk-forge - FoldersApi.GetFolderContents 未返回某些项目
- snowflake-cloud-data-platform - 可以在事务中执行访问权限语句吗?