我有两个Angular 应用程序,一个 shell 应用程序和一个内容应用程序在一个MonoRepo内。 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 {}
你知道缺了什么/错了什么吗?
谢谢!
1条答案
按热度按时间bf1o4zei1#
我遇到了完全相同的问题。我遇到的问题与Angular模块的导入有关。我在我的微前端中导入了Angular的
BrowserModule
,这是错误的。这个模块应该只在你的shell应用程序的根模块中导入。微前端应该只导入
CommonModule
。如果您导入BrowserModule
,这将中断Angular运行时并导致错误,如无法正确捕获事件。