What is the difference between Backbone.history.navigate and this.router.navigate?
Why would sometimes the former work while later won't?
What is the difference between Backbone.history.navigate and this.router.navigate?
Why would sometimes the former work while later won't?
If you look at the Backbone source, you'll see that
Router.prototype.navigateis simply a proxy toBackbone.history.navigatewhich you can call anywhere without the need for a router instance.Routing is handled in a global, namespaced in Backbone,
Historyinstance.This is meant to let developer create their own
Historyclass and then to overwrite theBackbone.historyproperty to globally change the routing behaviour.The
Historyclass isn't documented much, but it's well commented in the source.Also, having a proxy to
navigatein theRouterclass makes it easy to hook our own behaviour in the router directly.As to why sometimes it doesn't work is probably because you're trying to do
this.router.navigatein a class wherethis.routerdoesn't exist.