Twitter 如何在不重新加载页面的情况下更改 url?

How twitter changes url without reloading page?

最近我注意到,如果我们在我们的个人资料 view/url (http://twitter.com/profileName) 中单击我们的一条推文以在弹出窗口中查看其详细信息,url 会发生变化(http://twitter.com/profileName/status/statusId) 无需重新加载页面(未使用 url 中的 #)。

经过进一步调查,我注意到 window.history 发生了变化,来自:

{ title: "profileName (@profileName) | Twitter" }

至:

{ inOverlay: true, rollbackCount: 1 }

我目前正在开发自己的单页应用程序堆栈,并坚持编写自己的路由器 - 期待针对当前 # 使用趋势的替代方案,并认为了解这个 Twitter hack 可以帮助我一点。

他们使用 HISTORY API:

window.history.pushState("", "", '/newpage');

参考:https://blog.twitter.com/2012/implementing-pushstate-for-twittercom