背景: vue-cli4 配置vue-router 为history模式 , 跳转子路由后页面正常,但是刷新页面访问不到了
原因: 因为一般vue脚手架的默认路由配置时hash模式,为了解决直接打开打包文件页面空白的问题,会在config>index.js 下,把build的assetsPublicPath:'/',改成assetsPublicPath:'./';
但变成history路由模式时,就要改回来
解决方案:
1. 设置 assetsPublicPath:'/',
2. (可无)
devServer: {
open: true,
host: 'localhost',
port: 8080,
https: false,
hotOnly: false,
// http 代理配置
proxy: {
'/api': {
target: 'http://127.0.0.1:3000/api',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
historyApiFallback: true, /
before: (app) => {}
},
网友评论