前端路由原理
2020-05-31 本文已影响0人
SkyBlue丶ly
一,路由方式
1,hash(url后面带#)

1)hash变化会触发网页跳转,即浏览器的前进、后退
2)hash变化不会刷新页面,SPA必需的特点
3)hash永远不会提交到server端(完全属于前端)
2,h5 history(seo更好)

1)用url规范的路由,但跳转时不刷新页面
2)history.pushState(切换路由,window.onpopstate无法监测)
3)window.onpopstate(监听浏览器的前进、后退)
4)node服务端处理h5 history模式
