[英]HistoryApiFallback not working on Webpack 4 (with React Router 4 and nested routes)
上下文:使用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树。
显然添加:
<base href="/" />
放在index.html
的head标签上就足以解决此问题。 米普
我发现,如果添加:
output: {
publicPath: '/'
}
到webpack.config.js,那么您不需要添加
<base href="/" />
到index.html
请参阅: webpack-dev-server,historyApiFallback不起作用(webpack-4,react-router-4)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.