[英]webpack-dev-server historyApiFallback doesn't work
我正在尝试实现我的客户端渲染版本。 因此,我想处理从index.html
导入的router.js
路由。
所以我添加了一个historyAPIFallback
但它似乎不起作用。
我尝试了两种方法都指向localhost/post/1/test
,
// webpack.config.js
devServer: {
port: 3000,
historyApiFallback: {
rewrites: [{ from: /.*/, to: './src/index.html' }],
},
},
这输出:
Uncaught SyntaxError: Unexpected token '<'
指向第一个<html>
标签。
// webpack.config.js
devServer: {
port: 3000,
historyApiFallback: {
index: './src/index.html',
},
},
这输出:
GET http://localhost:3000/post/1/index.js net::ERR_ABORTED 404 (Not Found)
任何想法来解决我做错了什么?
对我index.html
解决方案是在我导入index.js
index.html
中添加/
前:
<script src="index.js"></script>
后:
<script src="/index.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.