URL更改方案
URL的hash
-
URL的hash
- URL的hash也就是锚点(#), 本质上是改变window.location的href属性.
- 我们可以通过直接赋值location.hash来改变href, 但是页面不发生刷新
HTML5的history模式:pushState
- history接口是HTML5新增的, 它有五种模式改变URL而不刷新页面.
- history.pushState()
HTML5的history模式:replaceState
- history.replaceState()
HTML5的history模式:go
-
history.go()
- 必须配合history.pushState进行使用
-
补充说明:
- 上面只演示了三个方法
- 因为 history.back() 等价于 history.go(-1)
- history.forward() 则等价于 history.go(1)
- 这三个接口等同于浏览器界面的前进后退。