vue-router.replace 是什么原理啊?

  1. 请教一下vue-router.replace的实现原理是什么?怎么就移除当前的历史记录?怎么实现将hash替换的?
阅读 5.2k
2 个回答

history.replaceState 相似,会替换当前的地址访问历史记录

vue-router , hash模式下,是通过这个方法来
如果支持pushState ,则用history.replaceState , 如果不支持,则用replace

// 来自vue-router源码: src/history/hash.js
function replaceHash(path) {
    if (supportsPushState) {
        replaceState(getUrl(path))
    } else {
        window.location.replace(getUrl(path))
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题