號樓關Alexey's answer,這可能迫使骨幹的歷史/路由器「改道」當前的URL,就好像它觸發重新加載。
如果navigate
的典型調用由於已經位於同一個url上而失敗/返回任何內容,並且在這些情況下調用loadUrl
來強制執行,您實際上可以調用detect。
例如,我的整個網站的內部鏈接的處理程序是這樣的:
// `Backbone.history.navigate` is sufficient for all Routers and will
// trigger the correct events. The Router's internal `navigate` method
// calls this anyways.
var ret = Backbone.history.navigate(href, true);
// Typically Backbone's history/router will do nothing when trying to load the same URL.
// In some cases (links with .allow-reload), we want it to re-fire the same route.
// We can detect when Backbone.history.navigate did nothing, and force the route.
if (ret === undefined && $link.hasClass('allow-reload')) {
Backbone.history.loadUrl(href);
}