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

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

作者: 壹点微尘 | 来源:发表于2022-04-11 15:05 被阅读0次

假设打包后的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

      本文链接:https://www.haomeiwen.com/subject/pzwisrtx.html