initial route not executed when going back through history
I have a router defined somewhat similar to the following (greatly
simplified for demo purposes here):
var MyRouter = Backbone.Router.extend({
routes: {
'': 'search',
'directions': 'directions',
'map': 'map'
},
search: function () {
// do something
},
directions: function () {
// do something
},
map: function () {
// do something
},
initialize: function () {
this.listenTo(myModel, 'change', this.updateNavigation);
Backbone.history.start({ pushState:true });
},
updateNavigation: function () {
var selected = myModel.get('selected');
this.navigate(selected);
}
});
The history entries are all getting created properly by the
updateNavigation call, and when I hit the back-button to go back through
the history I've generated, the routes fire for each of the entries, that
is until I get to the initial entry. At that point, even though the url
has updated with that history entry, the route that should interpret the
url at that point does not fire. Any idea what might be going on here? Am
I making some bad assumptions about how history works?
EDIT:
It seems I get inconsistent results - it's not always just the initial
entry that doesn't execute, it's sometimes anything after the first time
I've went back one through history. That is, I click the back-button once,
the url changes, the routes fire properly. I hit it again, the url
changes, the routes don't fire. It smacks of me doing something wrong, but
I haven't a clue.
No comments:
Post a Comment