vue 打包项目部署到服务器非根目录后白屏或者404

假设打包后的dist文件内容需要部署到非根目录http.xxx.com/m子路径下,解决步骤如下:

1、修改vue.config.js中的publicPath

module.exports = {
  publicPath: "/m/", //打包后部署在一个子路径上http:xxx/m/
  productionSourceMap: false,
  devServer: {
    proxy: "http://xxxx.com", //测试或正式环境域名和端口号
  },
};

2、修改路由router的/index.js

const router = new VueRouter({
  mode: "history",//路由模式
  base: "/m/",//部署的子路径
  routes,
});

export default router;

参考文章:https://www.jianshu.com/p/8dcf5e78c4c1

你可能感兴趣的:(vue 打包项目部署到服务器非根目录后白屏或者404)