vue项目部署(npm run build二级域名)

1,342 阅读1分钟

vue脚手架 默认启动打开的路由后 自动加 # 号

项目涉及需求:访问二级域名 才是该页面 

eg:xxx.com/xx 才是本项目的内容

修改如下:

router:index.js 去掉 # 号

const router = new Router({
  mode: 'history',
  base: '/md',
  routes: [
    {
      path: '*',
      component: notFound
    },
    {
      path: '/',
      name: 'xx',
      component: xx
    }
  ]
})

打包npm run build 生成 index.html 需要更换一下位置:

config/index.js  (需要改动3个地方,如下)

module.exports = {
  build: {
    env: env,
    index: path.resolve(__dirname, '../dist/md/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist/md'),
    assetsPublicPath: '/md/',

然后需要服务器改一下地址指向这个项目就可以了