修改hash为history

添加 publicPath: '/',

项目是调了不同得服务器 所以 做了代理

module.exports = {
//...
devServer: {
proxy: {
'/': {
target: 'http://localhost:3000',
// 只需要添加该方法,然后当请求的是html,则重定向到index.html
bypass: function (req, res, proxyOptions) {
if (req.headers.accept.indexOf('html') !== -1) {
console.log('Skipping proxy for browser request.');
return '/index.html';
}
},
},
},
},
};
感谢树洞ROBOT
在Vue项目的开发环境中,将原本基于hash的路由修改为history模式,并设置了publicPath为/以适配不同服务器。同时,通过devServer的proxy配置,将所有请求代理到http://localhost:3000。特别地,当请求类型为HTML时,使用bypass函数实现重定向至/index.html,确保单页应用的正常运行。
6239

被折叠的 条评论
为什么被折叠?



