I have a working app using Backbone 0.5.3, which is no longer working using backbone 0.9.2.
I identified that Router.navigate() doesn't call my route for some reason.
Here's my Router:
var Router = Backbone.Router.extend({
routes: {
'/mypage': 'mypage',
},
mypage: function() {
// show page ...
}
});
Calling the route manually like so works fine:
Router.mypage()
I also tried to overwrite backbone's .navigate method to debug my app ...
var Router = Backbone.Router.extend({
routes: {
'/mypage': 'mypage',
},
navigate: function(fragment, options) {
console.log("navigate called");
Backbone.history.navigate(fragment, options);
},
mypage: function() {
// show page ...
}
});
... it seems that .navigate is called but ...
Backbone.history.navigate(fragment, options);
... just doesn't call the route.
I'm using PushState, here's my initial call:
Backbone.history.start({
root: '/',
pushState: true,
silent: true
});
Already tried it without the root and silent parameters - no success.
Again: This works using Backbone 0.5.3.
Thanks to everyone leaving a reply!
Achim
You have to set the trigger option for the navigate method, e.g:
Router.navigate("/mypath", {trigger: true})
From the fine manual:
extend
Backbone.Router.extend(properties, [classProperties])
Get started by creating a custom router class. [...] Note that you'll want to avoid using a leading slash in your route definitions:
I'm guessing that you simply need to remove the leading slashes from your routes
, for example:
routes: {
'mypage': 'mypage',
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With