Reputation: 222929
I tried to use backbone with a pushstate:
$(document).ready(function(){
var App = Backbone.Router.extend({
routes: {
"/": "homepage",
"/questions": "questions"
},
homepage: function() {
console.log('why');
},
questions: function() {
console.log('this is not working?');
}
});
var the_app = new App();
$("a").click(function(ev) {
the_app.navigate( $(this).attr("href"), true);
return false;
});
Backbone.history.start({pushState: true});
})
The problem is that whenever I click a link like one of this:
<a href="/"> home </a>
<a href="/questions"> questions</a>
<a href="/justlink"> just link</a>
Location in the browser changes without reloading, but the function, associated with it and which I already defined in routes, does not executes. Any idea what have I done wrong?
Upvotes: 3
Views: 1091
Reputation: 434945
From the fine manual:
extend
Backbone.Router.extend(properties, [classProperties])
[...] Note that you'll want to avoid using a leading slash in your route definitions:
You want your routes
to look like this:
routes: {
"": "homepage",
"questions": "questions"
}
Demo: http://jsfiddle.net/ambiguous/ybPcg/
Upvotes: 4