前端路由规则

前端路由规则

  • 前端路由的核心是改变URL,但是页面不进行整体的刷新
  • URL的hash也就是锚点(#), 本质上是改变window.location的href属性
  • 我们可以通过直接赋值location.hash来改变href, 但是页面不发生刷新

HTML5的history模式:pushState

  • history接口是HTML5新增的, 它有五种模式改变URL而不刷新页面
    • history.pushState({},'','url')
      • 将url压入栈结构
      • 栈结构的特点是先进后出
      • 可以返回
    • history.replaceState({},'','url')
      • 替换url
      • 不能返回
    • history.back()
      • 返回
    • history.forward()
      • 前进
    • history.go()
      • history.go(-1)等价于history.back()
      • history.go(1)等价于history.forward()
posted @ 2020-03-12 19:52  懒惰ing  阅读(564)  评论(0编辑  收藏  举报