我正在尝试使用Backbone的pushState阻止整页重新加载.当我从视图的事件中调用navigate()时,我看到下面标记为// 1但不是// 2的消息.此外,当我尝试打开相同的选项卡时,页面会再次重新加载.
我必须自己停止活动吗?我尝试使用jQuery的preventDefault(),它确实阻止了页面重新加载,但我没有在任何地方看到过这种情况.
以下是我目前的代码:
App.Router = Backbone.Router.extend({
routes:{
"analytics":"analytics"
, "realtime":"realtime"
}
, analytics:function(page) {
console.log("analytics route hit: %o", page); // 2
}
, realtime:function(page) {
console.log("realtime route hit: %o", page); // 2
}
});
App.TabSetView = Backbone.View.extend({
initialize:function() {
this.collection.bind("reset", this.render, this);
this.collection.bind("add", this.render, this);
this.collection.bind("change", this.render, this);
this.collection.bind("remove", this.render, this);
}
, events:{
'click li.realtime a': "onRealtime"
, 'click li.analytics a': "onAnalytics"
}
, render:function() {
// omitted for brevity
}
, onAnalytics:function() {
console.log("onAnalytics"); // 1 …Run Code Online (Sandbox Code Playgroud) backbone.js ×1