【发布时间】:2021-07-01 01:17:54
【问题描述】:
我正在尝试实现我的客户端渲染版本。因此,我想处理来自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)
有什么办法可以解决我做错的事情吗?
【问题讨论】:
标签: javascript webpack router webpack-dev-server