vue-cli3.0配置多页history路由模式

一、在对应的多页目录下的router.js配置historyhtml

const router =  new Router({
  base: '/mobile/share',
  mode: 'history',
  },

注:router里面的base属性是项目部署服务器的目录路径,例如你的项目访问路径是www.xxx.com/mobile/share
二、在vue.congig.js添加代码vue

configureWebpack: {
        devServer: {
            historyApiFallback: {
                verbose: true,
                rewrites: [
                    { from: '/xx', to: '/yy.html'}
                ]
            }
        }
    },

注:from指你多页中进入其中一个页面index的路由路径,to表示重写到yy.html 至于多页配置自行搜索,注意的是修改vue.config.js须要从新启动才会生效。
三、重启输入localhost:8080/xx就能够访问到yy.html的代码
补充:若是部署到nginx服务器,发现报404,就须要nginx部署修改下代码nginx

location / {
            root   /software/vue/dist;
            index  index.html;
                try_files $uri $uri/ /index.html;
        }
        location /xx {
                root   /software/vue/dist;
                index  yy.html;
                try_files $uri $uri/ /yy.html;
        }

root:项目dist下面的文件部署的根目录服务器

相关文章
相关标签/搜索