nginx部署vue前端问题

// router/index.js
export default new Router({
  mode: 'history',
  base: '/data',
  routes: constantRouterMap.concat(asyncRouterMap)
})

// vue.config.js
{
    ...
    publicPath: './',
    outputDir: 'dist',
    ...
}
<div id="app"></div>
<script src="/data/static/icon/iconfont.js"></script>

image.png

nginx配置

location / {
    root   html;
    index  index.html index.htm;
}
# 访问这个
location ^~ /web-ai/ {
    alias   html/dist/;
    index  index.html index.htm;
}

文件路径
image.png
history模式,并且每一个都有一个前缀/data,部署之后所有路由懒加载的页面会404,比如image.png
这样是没问题的,但是这样image.png
点击对应页面的时候就是404

http://localhost/web-ai/

http://localhost/data/js/chunk-17662e9e.02b4f0b6.js
阅读 1.6k
1 个回答

publicPath 改为 ./

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题