我正在尝试从此格式重定向网址:http://localhost:8080/setup/xyz/?code=some-code
对此:http://localhost:8080/app/#/setup/xyz/?code=some-code
我已经尝试过代理和重写:
historyApiFallback: {
rewrites: [
{ from: /^\/$/, to: '/index.html' },
{ from: /^\/app/, to: '/app.html' },
{ from: /^\/setup/, to: '/app/#/setup' },
]
},
但它似乎不起作用。有没有办法使用开发服务器编写 301 重定向?
最佳答案
尝试配置 devServer
https://itsopensource.com/how-to-serve-api-locally-with-webpack/
const data = require("./data.json");
module.exports = {
mode: "development",
entry: "./src/index",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "build")
},
plugins: [],
devServer: {
before: function(app) {
app.get("/getData", function(req, res) {
res.json(data);
});
},
open: true,
port: 3000
},
resolve: {
extensions: [".js"]
},
module: {}
};
关于webpack - 使用 Webpack 开发服务器进行 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49055008/