我有个问题。我创建了一个 url 缩短网站,typescript它是一个单页网站,但可以更改路线。在我使用的这个项目中webpack,对于我使用的开发服务器webpack-dev-server以及返回index.html几乎所有路由,我在以下位置编写了这段代码webpack.config.js:
devServer: {
static: {
directory: path.join(__dirname, "dist"),
},
compress: true,
proxy: {
"/**": {
target: "/index.html",
secure: false,
bypass: function (req, res, opt) {
if (
req.path.indexOf("/img/") !== -1 ||
req.path.indexOf("/public/") !== -1
) {
return "/";
}
if (req.path.indexOf("/build.css") !== -1) {
return "/build.css";
}
if (req.headers.accept.indexOf("html") !== -1) {
return "/index.html";
} else return;
},
},
},
}
Run Code Online (Sandbox Code Playgroud)
现在我想index.html为应用程序的 vercel 服务器启用此功能(每次路由更改时返回)。这时,当我改变路线时,我会得到404页面。但我想得到index.html。我进行了很多搜索来实现我想要的,并且测试了一些方法,但我无法做到我想要的。 …