0

I am using jQueryMobile and Backbone and am having problems with custom or dynamically generated back buttons not going back in the history properly. I am using the data-rel="back" attribute on anchor tags as described in the documentation: http://view.jquerymobile.com/1.3.2/dist/demos/widgets/headers/

My back button code is as follows:

<a href="#" data-rel="back" data-icon="arrow-l" data-iconpos="notext"></a>

When I click the back button it doesn't seem to use the data-rel="back" functionality at all and instead goes to the page as specified in the href attribute, which in most cases is '#' or empty.

This can be confirmed by hard-coding a different href value - the back button will go that page, and not the previous page in the history as it's supposed to.

I suspect it to be a conflict between Backbone and jQuery Mobile and the configurations necessary to get them to work nicely (let Backbone handle page transitions), but do not know how to get around it.

As described in the jQM docs I had to set the following in a mobile-config file:

$.mobile.ajaxEnabled            = false;
$.mobile.linkBindingEnabled     = false;
$.mobile.hashListeningEnabled   = false;
$.mobile.pushStateEnabled       = false;
$.mobile.changePage.defaults.changeHash = false;

Note: I've reviewed many of the posts on this subject on SO before posting and there doesn't seem to be a suitable solution presented in any of the responses.

4

2 回答 2

0

我遇到了同样的情况,发现一个简单的解决方案就是创建一条新路线并用它来追溯历史。

例如,只需将href后退按钮的值设置为#back

<a href="#back" data-icon="back" data-rel="back" title="Go back">Back</a>

然后添加一条新路线

routes: {
    ...   
    'back' : 'back',
    ...
}

而在处理路线的代码中,只需退后两步即可。

appRouter.on('route:back', function() {
    history.go(-2);
});

需要返回 -2 以取消#back路线。

于 2014-08-24T19:39:27.787 回答
0

我想到了。这是实现此处找到的解决方案的组合: jQuery Mobile +bone.js:返回时的页面转换

为我想要绑定自定义事件的所有锚标签添加一个属性“数据绕过”,因为我正在使用 Backbone Boilerplate 项目中的一段代码来处理相对 url。

于 2013-08-17T06:22:24.103 回答