使用带有triggerRoute = true;的导航方法时,页面可以很好地导航到新页面,但不会更新历史记录。
当点击Android设备(Nexus S)上的后退按钮时,会弹出历史记录,但不会进行导航。
如果我为triggerRoute传递false,然后调用Backbone.history.loadUrl();,那么back按钮确实可以工作,但有点不稳定。
导航方法有这样的注释...
// URL-encoding the fragment in advance. This does not trigger
// a `hashchange` event.在读了几篇文章后,我觉得使用导航方法是正确的方法,应该更新历史记录……
代码片段...
er.getApp().getController().navigate('home', true);或
er.getApp().getController().navigate('home');
Backbone.history.loadUrl();jquerymobile和backbone组合是否存在已知的路由问题。这里较旧的答案与较早版本的backbone.js相关,不再有效...
发布于 2011-11-13 02:17:54
好的。找到了解决方案。基本上,告诉jquerymobile不要对back按钮和hashchange事件做任何事情,让backbone完全处理它。
在index.html,appLoading事件处理程序中,有代码将Jquerymobile绑定到back按钮,删除了它。
//removed this part
document.addEventListener("backbutton", function(){
if (window.history.length > 0) {
window.history.back();
return false;
}
navigator.app.exitApp();
}, true);
// Since we are using the backbone router we want to disable
// auto link routing of jquery mobile.
// The code below for mobileinit
// notice the last two settings
$(document).bind("mobileinit", function() {
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
});https://stackoverflow.com/questions/8100846
复制相似问题