vue-router

泄露秘密 提交于 2019-12-06 14:27:57

vue-router通过hashHistory interface两种方式实现前端路由,更新视图但不重新请求页面”是前端路由原理的核心之一,目前在浏览器环境中这一功能的实现主要有两种方式

  1. hash ---- 利用URL中的hash(“#”)

  2. 利用History interface在 HTML5中新增的方法;History.pushState()

那么,我们要选择用哪种方式呢?

在vue-router中,它提供mode参数来决定采用哪一种方式,选择流程如下:

mode 参数:

let routes = [{
path:'/',
redirect:'/index',
meta:{title:'index',keepLive:true}
},
{
path:'/index',
component:require('./views/index.vue'),
meta:{title:'index',keepLive:true}
}
]

let router = new Router({
mode:'hash',
routes:routes
})
  • 默认hash

  • history 注:如果浏览器不支持history新特性,则采用hash方式

  • 如果不在浏览器环境则使用abstract(node环境下)

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!