0%

vue history 模式打包部署配置指南

项目为一级目录

1.在项目里设置vue-router为history模式:

const router = new VueRouter({
    mode: 'history',
    routes: [...]
})

2.服务端配置(nginx 环境):

location / {
    try_files $uri $uri/ /index.html;
}
项目为二级目录 ( subWeb 为对应的二级目录名称)

1.在项目里设置vue-router为history模式:

const router = new VueRouter({
    mode: 'history',
    base:'/subWeb',
    routes: [...]
})

2.在vue.confing.js配置:

module.exports = {
  publicPath:"/subWeb"
}

3.在入口文件中index.html 的head 标签内加入:

<meta base ="/subWeb/">

4.服务端配置(nginx 环境):

location /subWeb {
    try_files $uri $uri/ /subWeb/index.html;
}