三种路由Router

// Router原理


//页面路由
window.location.href = 'https://www.baidu.com'
history.back();   //回退

// hash路由
window.location = '#hash'
window.onhashchange = function(){
    console.log('current hash',window.lacation.hash)
    window.lacation.hash
}

//h5路由
history.pushState('name','Title','/path')
// 推进一个状态
history.pushState('test','Title','#test')
//替换一个状态
history.replaceState('test','Title','/index/test')

window.onpopstate = function(e){
    window.location.href    //全路径
    window.location.pathname   //绝对路径
    window.lacation.hash    //hash路由
    window.lacation.search    
    console.log('h5 router change',e.state)
}

你可能感兴趣的:(三种路由Router)