ModuleFederationPlugin 和 webpack:为什么我在路由错误的情况下尝试下载 /XXXX/main.js

问题描述 投票:0回答:1

我正在尝试更好地了解 Webpack 和 MFE。 构建了一个包含 2 个 React 模块的 React 容器。到目前为止效果很好。我还没有完成所有路由的实现,但每次我在 URL 中输入一些内容时:

http://localhost:4230/trainees/add

浏览器尝试获取新资源:

这是我的 MFE 配置:

        new ModuleFederationPlugin( {
            name : 'container',
            remotes : {
                trainer : 'trainer@http://localhost:4230/remoteEntry.js',
                trainee : 'trainee@http://localhost:4220/remoteEntry.js'
            },
            shared: ['react', 'react-dom', {
                'react-router-dom': {
                    singleton: true
                }
            }],
        })

如果我尝试在代码中使用

<Nav>
访问相同的网址,它会起作用...

这是正常行为吗?

谢谢

webpack webpack-module-federation mfe
1个回答
0
投票

找到了!

是webpack文件中的historyApiFallback。 我只是将其设置为 true:

 historyApiFallback: {
            index : true
 },
© www.soinside.com 2019 - 2024. All rights reserved.