我用同样的答案从jevakallio,但我有这样的评论者杰伊·库马尔有同样的问题:routesHit
不减去这样打appRouter.back()
足够的时间将用户退出应用程序的,所以我加了3条线:
var AppRouter = Backbone.Router.extend({
initialize: function() {
this.routesHit = 0;
//keep count of number of routes handled by your application
Backbone.history.on('route', function() { this.routesHit++; }, this);
},
back: function() {
if(this.routesHit > 1) {
//more than one route hit -> user did not land to current page directly
this.routesHit = this.routesHit - 2; //Added line: read below
window.history.back();
} else {
//otherwise go to the home page. Use replaceState if available so
//the navigation doesn't create an extra history entry
if(Backbone.history.getFragment() != 'app/') //Added line: read below
this.routesHit = 0; //Added line: read below
this.navigate('app/', {trigger:true, replace:true});
}
}
});
,并使用RO uter方法导航回:
appRouter.back();
新增线路:
一日一:从routesHit
减去2,那么当其重定向到“返回”页面,它会获得1点所以它实际上是像你这样刚减1。
第二个:如果用户已经在“家”,不会是一个重定向,所以不要做任何事情routesHit
。
第三个:如果用户是他在哪里开始并且被发送回“家”,设置routesHit = 0
,那么当重定向到“家”时routesHit
将再次为1。
这种方法统计包括浏览器后退导航在内的所有路线。假设我在我的应用程序内导航到3条路线,那么routesHit将为3.现在使用浏览器后退按钮不会减少routesHit(而是增加它),浏览器最终会将您从应用程序中移出。 – 2013-09-18 08:40:08