我正在尝试实现我的客户端渲染版本。因此,我想处理从 router.js
导入的 index.html
的路由。
所以我添加了一个 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)
有什么办法可以解决我做错的地方吗?
答案 0 :(得分:0)
对我有用的解决方案是在我导入 /
的 index.html
中添加 index.js
之前:
<script src="index.js"></script>
之后:
<script src="/index.js"></script>