javascript - webpack-dev-server historyApiFallback 不起作用
问题描述
我正在尝试实现我的客户端渲染版本。因此,我想处理从我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>
标签。
- 来自stackoverflow(这似乎是一个旧的解决方案)
// 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
前:
<script src="index.js"></script>
后:
<script src="/index.js"></script>
推荐阅读
- html - 如何制作一个html滚动页面
- python - 手动更改的量化权重未反映在 state_dict()
- c++ - 错误 LNK2019:函数 _main 中引用的未解析外部符号“public:__thiscall RNG::RNG(unsigned __int64)”(??0RNG@@QAE@_K@Z)
- apache-nifi - 恢复 NiFi 项目
- asp.net-mvc - 使用 MVC 5 创建 OAuth2.0 登录应用程序
- java - 弄清楚用户是否输入了数值或其他内容?
- javascript - 如何在我的 Vuex 商店中返回 Promise 而不会收到错误消息?
- html - 这个网格容器的高度是如何计算的?
- excel - 在 Excel 中根据两个或多个条件插入行
- r - 面临访问闪亮模块动态输入值的问题