I’m new in backbone 0.9.1.
I found when I change hash and I can not trigger hash change in my demo.
My URL is http://[…%5D/backbone/#help. I think I should receive a alert message “help”, but I’m not.
$(function() {
var App = {
Controllers:{},
initialize: function(){
new App.Controllers.Routes();
var h = new Backbone.History();
h.start({root: '/backbone/'});
}
};
App.Controllers.Routes = Backbone.Router.extend({
routes: {
"help": "help",
"search/:query": "search",
},
help: function() {
alert("help");
},
search: function(query) {
alert("search");
}
});
App.initialize();
});
Is there some misunderstanding or misuse?
You don’t need to instantiate a History object yourself. Also, if you’re not using pushstate, you don’t need to specify the
rootin the start options.So, your initialize method should look like this: