vue中如何改变url但是网页不发生刷新

459 阅读1分钟
  1. 改变location的hash值
location.hash="aaa"</br>
 会在url中添加aaa
  1. 通过html中的history属性来修改
history.pushState({},'','home')
// pushState(data,title,url)
该方法会使页面跳转至/home页面,history的数据结构是栈

history.replacState({},'','title')
该方法会直接清空栈并将元素压进栈尾

history.go(int a)
该方法决定栈的方向,当为正数时,元素进栈;当为负数时,元素出栈。

history.go(1)等价于history.forward()
history.go(-1)等价于historry..back()