美文网首页
vue history 路由模式打包发布到服务器设置

vue history 路由模式打包发布到服务器设置

作者: aimee66 | 来源:发表于2019-04-30 14:30 被阅读0次

    要求描述

    页面访问地址
    首页:https://hello.haha.com/world
    用户中心 :https://hello.haha.com/world/user

    路由设置

    路由配置js 设置 mode 为history ,这样会去掉#号 和正常的路由地址一样

    export default new Router({
      mode: 'history',
      routes: [
        {
          path: '/world', // 注意 路由的path 需要和页面的地址保持一致,即域名后的二级目录都得一样,否则会报错
          name: 'index',
          component: index
        },
        {
          path: '/world/user', 
          name: 'user',
          component: user
        },
        {
          path: '*',
          redirect: {name: 'index'}
        }
      ]
    })
    
    

    ngix服务器配置

    vue官方文档推荐

    在这里插入图片描述

    多层级目录的项目配置

    例如:项目区分pc 和 h5 项目,且两个项目为独立的
    主目录为:hello.haha.com
    层级:pc: /hello-pc/
    h5: /hello-h5/
    用户访问链接:pc : https://hello.haha.com/hello-pc/world
    https://hello.haha.com/hello-pc/world/user

    用户访问链接:h5 : https://hello.haha.com/hello-h5/world
    https://hello.haha.com/hello-h5/world/user

    nginx 这时候可以这么配置:

    location /hello-pc/ {
        try_files $uri $uri/ /hello-pc/index.html
    }
    
    location /hello-h5/ {
        try_files $uri $uri/ /hello-h5/index.html
    }
    

    相关文章

      网友评论

          本文标题:vue history 路由模式打包发布到服务器设置

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