js监听url的hash变化和获取hash值
当浏览器浏览器的url进行变化时,浏览器默认是会去服务器将相应的资源给请求下来的,在不阻止默认行为的前提下,使用给url加锚点的方式(hash模式),让浏览器不跳转。
window.addEventListener('hashchange',()=>{
const value = location.hash
console.log(value)
switch(){
//对应操作
}
})
浙公网安备 33010602011771号