I've created a site in backbone and for various reasons I've decided I want to remove the hash in the URL. I've changed history.start from
Backbone.history.start();
to
Backbone.history.start({pushState: true, root: '/'});
but once I do that the routing stops working correctly.
My routing looks like this:
var Router = Backbone.Router.extend({
routes: {
"": "home",
"home": "home",
"artists": "artists",
}
});
var router = new Router;
router.on('route:home', function() {
console.log("home");
// Code
});
router.on('route:artists', function() {
console.log("artists");
// Code
});
//Backbone.history.start();
Backbone.history.start({
pushState: true,
root: '/'
});
if I run it without pushState it works fine, if I run it with pushState it doesn't reach the console.log("artists");
part and I don't understand why, could someone explain to me what I'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…