移动设备的后退按钮不起作用 -backbone.js 0.5.3 和 jquerymobile 1.0 RC2

发布于 2024-12-15 05:46:36 字数 724 浏览 4 评论 0原文

当使用带有 triggerRoute = true; 的导航方法时,页面可以正常导航到新页面,但历史记录不会更新。

当点击 Android 设备 (Nexus S) 上的后退按钮时,历史记录会弹出,但导航不会发生。

如果我为 triggerRoute 传递 false,然后调用 Backbone.history.loadUrl(); 那么后退按钮确实可以工作,但有点不稳定。

导航方法有这样的评论...

// 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 是否存在已知的路由问题和骨干组合。这里较旧的答案与骨干.js 的早期版本相关,并且不再有效......

When using the navigate method with triggerRoute = true; the page navigates fine to the new page but history is not updated.

When hitting the back button on an Android device (Nexus S), the history pops, but the navigation does not happen.

If I pass false for the triggerRoute and then call Backbone.history.loadUrl(); Then the back button does work but sort of erratically.

The navigate method has this comment ....

// URL-encoding the fragment in advance. This does not trigger
// a `hashchange` event.

After reading several posts, it seems to me that using the navigate method is the right way and should update the history...

Code snippet ...

er.getApp().getController().navigate('home', true);

OR

er.getApp().getController().navigate('home');
Backbone.history.loadUrl();

Is there a known routing issue with jquerymobile and backbone combination. Older answers here relate to earlier version of backbone.js and are not valid anymore ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天气好吗我好吗 2024-12-22 05:46:36

好的。找到了解决办法。基本上告诉jquerymobile不要对后退按钮和hashchange事件执行任何操作,并让backbone完全处理它。

在index.html的appLoading事件处理程序中,有将Jquerymobile绑定到后退按钮的代码,将其删除。

//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;
});

Ok. Found a resolution. Basically tell jquerymobile not to do anything with the back button and hashchange event and let backbone handle it completely.

In the index.html, appLoading event handler, there was code binding Jquerymobile to the back button, removed it.

//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;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文