vue 中 history 模式的配置和打包

  • 在使用 vue 进行项目开发中,默认的路由形式是 hash,表现形式就是 url 中始终带有 # 号,在后台管理类的项目中并不影响使用,但是在特殊场景,比如微信分享的H5链接中,微信会自动拼接参数,由于 # 的原因,路径中会出现两段由 ? 拼接的部分,为避免这种情况,形成较为规范的 url 形式,可以采用 history 模式
// 路由文件 index.js
const router = new VueRouter({
  mode: 'history',
  base: '/aa/',
  routes
})
// vue.config.js
module.exports = {
	publicPath: '/aa/', // 基本路径
}
  • base 和 publicPath 路径保持一致,值就是服务器域名下的文件夹目录,比如:www.xxxx.com/aa/,如果是根目录,直接写为 /
  • 配置 history 模式需要服务器支持,服务器具体配置见官网 后端配置
posted @ 2020-03-23 10:23  NorthHarbor  阅读(2036)  评论(0编辑  收藏  举报