0
点赞
收藏
分享

微信扫一扫

vue-Router实现原理

sunflower821 2022-01-31 阅读 49

前端路由概念

通过改变 URL,在不重新请求页面的情况下,更新页面视图

vue-Router两种模式

Hash — 默认值,利用 URL 中的hash("#") 
history-- 利用URL中的路径(/home)

如何设置路由模式

const router=new VueRouter({
    mode:'history',
    routes:[...]
})

mode 区别

  1. mode:“hash” 多了 “#”
http://localhost:8080/#/login
  1. mode:“history”
http://localhost:8080/home

HashHistory

hash("#")的作用是加载 URL 中指示网页中的位置。# 号后面的 hash值,可通过 window.location.hash 获取
特点:

HashHistory 拥有两个方法,一个是 push, 一个是 replace

HashHistory.push() 将新路由添加到浏览器访问历史的栈顶
replace()方法与push()方法不同之处在于,
它并不是将新路由添加到浏览器访问历史的栈顶,而是替换掉当前的路由
举报

相关推荐

0 条评论