我在MonoRepo中有两个Angular应用程序,一个外壳应用程序和一个内容应用程序。shell应用程序就像一个显示卡片的登录页面,点击它,内容应用程序就会显示出来。
在此内容应用程序中,我使用了mat-select控件,它不会关闭面板上的外部单击->问题!看起来外部的点击事件是由shell应用程序捕获的。如果我在shell应用程序中使用mat-select,一切都会正常工作。
这是我的shell webpack配置:
const webpack = require("webpack");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
module.exports = {
output: {
publicPath: "http://localhost:4200/",
uniqueName: "home",
},
optimization: {
runtimeChunk: false,
},
plugins: [
new ModuleFederationPlugin({
shared: {
"@angular/core": { eager: true, singleton: true },
"@angular/common": { eager: true, singleton: true },
"@angular/router": { eager: true, singleton: true }
},
}),
],
};内容: webpack配置:
const webpack = require("webpack");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
module.exports = {
output: {
publicPath: "http://localhost:4201/",
uniqueName: "contentModul"
},
optimization: {
runtimeChunk: false,
},
plugins: [
new ModuleFederationPlugin({
name: "content",
library: { type: "var", name: "content" },
filename: "remoteEntry.js",
exposes: {
ContentModule:
"./projects/content/src/app/content/content.module.ts",
},
shared: {
"@angular/core": { eager: true, singleton: true },
"@angular/common": { eager: true, singleton: true },
"@angular/router": { eager: true, singleton: true }
},
}),
],
};下面是我的路线:
import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { HomeComponent } from "./home/home.component";
import { PageNotFoundComponent } from "./static-pages/page-not-found/page-not-found.component";
import { loadRemoteModule } from "./utils/federation-utils";
const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
{
path: "content",
loadChildren: () =>
loadRemoteModule({
remoteName: "content",
remoteEntry: "http://localhost:4201/remoteEntry.js",
exposedModule: "ContentModule",
}).then((m) => m.ContentModule)
},
{ path: "**", component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}你知道遗漏了/错了什么吗?
谢谢!
发布于 2021-09-16 07:41:14
我也有同样的问题。我遇到的问题与Angular模块的导入有关。我在我的微型前端导入了Angular的BrowserModule,这是错误的。此模块只能导入到shell应用程序的根模块中。
微前端应该只导入CommonModule。如果改为导入BrowserModule,这将破坏Angular运行时,并导致错误,如未正确捕获事件。
https://stackoverflow.com/questions/67610895
复制相似问题