GitHub如何在不重载页面的情况下更改URL ?

时间:2022-08-26 11:28:04

Go to any GitHub page and click on any of the directories/files and observe how the URL changes but only part of the page is updated. There's no whole page reloading.

转到任何GitHub页面并单击任何目录/文件,观察URL如何更改,但只更新页面的一部分。没有整个页面重载。

How do I do something similar using jQuery?

如何使用jQuery做类似的事情?

Does this work on most browsers (I'm using Chrome)?

这对大多数浏览器都有用吗(我使用的是Chrome)?

2 个解决方案

#1


30  

They use the history API, or specifically, history.pushState().

它们使用history API,或者特定的history. pushstate()。

You can use this, jQuery is not required, but there are plugins such as history.js.

您可以使用它,jQuery不是必需的,但是有像history.js这样的插件。

This works on most browsers, namely Chrome, Safari and Firefox. IE10 and above supports this. In older IEs, you can fall back onto using the hash (window.location.hash).

这适用于大多数浏览器,即Chrome、Safari和Firefox。IE10和以上支持这一点。在较老的IEs中,您可以使用散列(window.location.hash)。

GitHub also blogged about this.

GitHub也对此发表了博客。

#2


4  

Github use PJAX (Ref). You may see about jquery-pjax here. Note that this feature is not covered support by all browser, there are some browser that cannot be use this benefits.

Github使用PJAX(Ref)。您可能在这里看到jquery-pjax。注意,这个特性并不是所有浏览器都支持的,有一些浏览器不能使用这个优点。

#1


30  

They use the history API, or specifically, history.pushState().

它们使用history API,或者特定的history. pushstate()。

You can use this, jQuery is not required, but there are plugins such as history.js.

您可以使用它,jQuery不是必需的,但是有像history.js这样的插件。

This works on most browsers, namely Chrome, Safari and Firefox. IE10 and above supports this. In older IEs, you can fall back onto using the hash (window.location.hash).

这适用于大多数浏览器,即Chrome、Safari和Firefox。IE10和以上支持这一点。在较老的IEs中,您可以使用散列(window.location.hash)。

GitHub also blogged about this.

GitHub也对此发表了博客。

#2


4  

Github use PJAX (Ref). You may see about jquery-pjax here. Note that this feature is not covered support by all browser, there are some browser that cannot be use this benefits.

Github使用PJAX(Ref)。您可能在这里看到jquery-pjax。注意,这个特性并不是所有浏览器都支持的,有一些浏览器不能使用这个优点。