Fri*_*c14 9 browser-history backbone.js
我有一个Backbone应用程序.我正在使用Backbone.history来启用后退按钮.我们有一个页面(设置),可以自动加载需要用户输入的弹出窗口.如果用户选择取消,我想返回上一页.我可以使用window.history.back()来做到这一点.
问题是,如果用户通过在浏览器中输入网址直接从其他网址(如google)转到该网页(应用#设置),我想将用户重定向到主页(app /)而不是返回去谷歌.
我无法找到任何方法来做到这一点.Backbone.history看起来像是从浏览器的后退按钮存储信息,因此即使它们刚刚到达应用程序,它也有历史记录.我也找不到查看上一个网址的方法.
这可能吗?
jev*_*lio 24
将后导航逻辑包装在您自己的方法中.也许在路由器上:
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
window.history.back();
} else {
//otherwise go to the home page. Use replaceState if available so
//the navigation doesn't create an extra history entry
this.navigate('app/', {trigger:true, replace:true});
}
}
});
Run Code Online (Sandbox Code Playgroud)
并使用路由器方法导航回:
appRouter.back();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22435 次 |
最近记录: |