【发布时间】:2013-05-18 07:18:53
【问题描述】:
在我的应用中..
当我加载页面或刷新页面时,我的路由器没有正确响应并调用默认视图方法。如果我使用其他链接来访问其他哈希 url... 也可以正常使用后退按钮。
即使在我加载页面时,我的启动功能也可以正常工作。但是当我加载页面并使用浏览器的后退按钮时,默认方法不会触发。
这是什么原因..这是我的代码:
define([
"backbone",
"../model/model",
"../collection/collection",
"../views/appView",
"../views/listView",
"../views/appViews"],
function(Backbone,appModel,collection,appView,listView,appViews){
var appRouter = Backbone.Router.extend({
routes:{
"":"defaultView",
"list":"listAItem",
"add":"listViewIt"
},
initialize:function(){
console.log("initiated....."); //works properly
},
defaultView:function(){
new appViews(); // not working..
},
listAItem:function(){
console.log("from listAItem");
// on click and using back button woks fine
},
listViewIt:function(){
new listView();
// on click and using back button woks fine
}
});
Backbone.history.start(); // removed and updated to where i call my app...
return appRouter;
})
现在我更新了我的 Backbone.history 以在启动我的应用程序后调用..现在我的初始方法(调用默认视图)但是当我在浏览器中使用我的后退/字体按钮时仍然无法正常工作..但重置工作正常。 .
如何解决..
这是我更新的代码:
$.when.apply(null,requests).done(function(){
var app = new router();
//on refresh works, but not working while use back / front button of browser use.
Backbone.history.start();
});
【问题讨论】:
-
是的,我做到了.. 更新了我的问题。
-
它工作正常...谢谢
标签: backbone.js backbone-routing