backbone.js history 里的 pushState 究竟是什么含义?
pushState support exists on a purely opt-in basis in Backbone. Older browsers that don't support pushState will continue to use hash-based URL fragments, and if a hash URL is visited by a pushState-capable browser, it will be transparently upgraded to the true URL. Note that using real URLs requires your web server to be able to correctly render those pages, so back-end changes are required as well. For example, if you have a route of /documents/100, your web server must be able to serve that page, if the browser visits that URL directly. For full search-engine crawlability, it's best to have the server generate the complete HTML for the page ... but if it's a web application, just rendering the same content you would have for the root URL, and filling in the rest with Backbone Views and JavaScript works fine.
看不太懂这一段,能举一个例子吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Backbone 的路由, 通过监听网址变化来起作用.. 这个题主先要了解.
还有要了解到, 其实有两种网址
/path
/#path
.. 这两个什么区别.旧的浏览器不支持其中一种, 因此 Backbone 提供了
pushState
的选项.关键词: HTML5 History API
自问自答一下吧,之前旧的浏览器只能通过hashchange来判断单页app地址的变化,而由于html5 history api的出现,允许通过/path 这样的模式来渲染页面,这种模式就叫做pushState,pushState设为true意味可以采用这种模式。在backbone里面,会判断浏览器对history api的支持,不支持的浏览器自动降格为hashchange的方式来切换页面。