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前端开发 backbone.js JavaScript

西行寺奈奈子 10 years, 8 months ago

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

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

真红·zero answered 10 years, 8 months ago

Your Answer