1.hash方式
URL的hash即锚点(#),本质上是改变window.location的href属性
可以直接通过赋值location.hash来改变href,但是页面不发生刷新
location.hash='aaa'
location.hash='/aaa'
这两个实际路径是一致的
路径显示:http://192.168.0.105:8080/#/aaa
即hash后面的值无论是否加/均是直接拼接在/#/之后的
2.history方式
history.pushState({},'','home')
history.pushState({},'','/home')
这两个实际路径是一样的
路径显示:http://192.168.0.105:8080/home
但是注意,如果加/表示直接在http://192.168.0.105:8080后面拼接,不加/表示相对当前路径进行改变
如:
history.pushState({},'','/about/1') 路径显示为http://192.168.0.105:8080/about/1
之后在该路径基础上进行操作
history.pushState({},'','2') 路径显示为http://192.168.0.105:8080/about/2