backbone.js history 里的 pushState 究竟是什么含义?

pushStatesupportexistsonapurelyopt-inbasisinBackbone.Olderbrowsersthatdon'tsupportpushStatewillcontinuetousehash-basedURLfragments,andifahashURLisvisitedbyapushState-capablebrowser,itwillbetransparentlyupgradedtothetrueURL.NotethatusingrealURLsrequiresyourwebservertobeabletocorrectlyrenderthosepages,soback-endchangesarerequiredaswell.Forexample,ifyouhavearouteof/documents/100,yourwebservermustbeabletoservethatpage,ifthebrowservisitsthatURLdirectly.Forfullsearch-enginecrawlability,it'sbesttohavetheservergeneratethecompleteHTMLforthepage...butifit'sawebapplication,justrenderingthesamecontentyouwouldhavefortherootURL,andfillingintherestwithBackboneViewsandJavaScriptworksfine.
看不太懂这一段,能举一个例子吗?
繁星淼淼
浏览 587回答 2
2回答

Qyouu

自问自答一下吧,之前旧的浏览器只能通过hashchange来判断单页app地址的变化,而由于html5historyapi的出现,允许通过/path这样的模式来渲染页面,这种模式就叫做pushState,pushState设为true意味可以采用这种模式。在backbone里面,会判断浏览器对historyapi的支持,不支持的浏览器自动降格为hashchange的方式来切换页面。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript