javascript - backbone.js history 里的 pushState 究竟是什么含义?
怪我咯
怪我咯 2017-04-10 14:28:05
[JavaScript讨论组]

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.

看不太懂这一段,能举一个例子吗?

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
天蓬老师

Backbone 的路由, 通过监听网址变化来起作用.. 这个题主先要了解.
还有要了解到, 其实有两种网址 /path /#path.. 这两个什么区别.

旧的浏览器不支持其中一种, 因此 Backbone 提供了 pushState 的选项.
关键词: HTML5 History API

怪我咯

自问自答一下吧,之前旧的浏览器只能通过hashchange来判断单页app地址的变化,而由于html5 history api的出现,允许通过/path 这样的模式来渲染页面,这种模式就叫做pushState,pushState设为true意味可以采用这种模式。在backbone里面,会判断浏览器对history api的支持,不支持的浏览器自动降格为hashchange的方式来切换页面。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号