[英]HistoryApiFallback not working on Webpack 4 (with React Router 4 and nested routes)
Context: Trying out RR4 with webpack 4 (devServer: {apiHistoryFallback: true} Sample Webpack 4 config 上下文:使用Webpack 4尝试RR4(devServer:{apiHistoryFallback:true} 示例Webpack 4配置
http://localhost:8080/reports works when cut and pasted into the address bar (aka history fallback is working) and I can click a link for /reports/8, as I have added a nested route to the component at /reports 将http:// localhost:8080 / reports剪切并粘贴到地址栏中后即可使用(又名历史回退有效),我可以单击/ reports / 8的链接,因为我已在/ reports中向该组件添加了嵌套路由
<Route path=${match.path}/:reportId component={ReportDetail}/>
but cut and paste http://localhost:8080/reports/9 into the address bar and I get a blank screen and a: 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.
但是将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.
Tried setting the contentBase for devServer but that didn't resolve the issue. 尝试为devServer设置contentBase,但不能解决问题。
This functionality worked fine in Webpack 3 and RR3. 此功能在Webpack 3和RR3中运行良好。 Not sure whether to bark up the Webpack or React Router tree. 不确定是打包Webpack还是React Router树。
Similar issue to this one but for Webpack 3 与这个类似的问题,但对于Webpack 3
Apparently adding: 显然添加:
<base href="/" />
to the head tag of your index.html
is enough to fix this issue. 放在index.html
的head标签上就足以解决此问题。 Meep 米普
I found out that if you add: 我发现,如果添加:
output: {
publicPath: '/'
}
to your webpack.config.js then you don't need to add 到webpack.config.js,那么您不需要添加
<base href="/" />
to index.html 到index.html
see: webpack-dev-server, historyApiFallback not working (webpack-4, react-router-4) 请参阅: webpack-dev-server,historyApiFallback不起作用(webpack-4,react-router-4)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.