Reputation: 53843
I'm trying to learn Backbonejs so I created my first route:
var Router = Backbone.Router.extend({
routes: {
"": "home"
}
});
var router = new Router();
router.on("route:home", function() {
alert('the router works!!');
});
alert('after the router!!');
I then navigated my browser to www.mydomain.com/thefolder/
which shows me the alert after the router!!
, but unfortunately I don't get to see the router works!!
. I tried inserting various routes, such as "/"
, "thefolder/"
and "/thefolder/"
, but nothing seems to work.
Does anybody know what I'm doing wrong here?
Upvotes: 1
Views: 54
Reputation: 33334
If I may quote the doc for Backbone.Router
During page load, after your application has finished creating all of its routers, be sure to call
Backbone.history.start()
, orBackbone.history.start({pushState: true})
to route the initial URL.
Add Backbone.history.start();
after your router declaration and you callback should be called.
See http://jsfiddle.net/nikoshr/wTU58/ for a demo
Upvotes: 4