HistoryApiFallback 不适用于 Webpack 4(使用 React Router 4 和嵌套路由)

Und*_*per 2 javascript webpack webpack-dev-server react-router-v4

上下文:使用 webpack 4 尝试 RR4 (devServer: {apiHistoryFallback: true} Webpack 4 配置示例

http://localhost:8080/reports在剪切并粘贴到地址栏时有效(又名历史回退正在工作),我可以单击 /reports/8 的链接,因为我已在 /reports 处添加了到组件的嵌套路由

<Route path=${match.path}/:reportId component={ReportDetail}/>

但是将http://localhost:8080/reports/9剪切并粘贴到地址栏中,我得到一个空白屏幕和一个: Refused to execute script from 'http://localhost:8080/reports/main.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. 尝试为 devServer 设置 contentBase 但这并没有解决问题。

此功能在 Webpack 3 和 RR3 中运行良好。不确定是否要吠叫 Webpack 或 React Router 树。

与此类似的问题,但针对 Webpack 3

Und*_*per 5

显然添加:

<base href="/" />

到你的 head 标签index.html就足以解决这个问题。米普


归档时间:

查看次数:

1287 次

最近记录:

7 年,6 月 前