I get Cannot call 'start' of undefined
when calling...
Backbone.history.start()
When running some checks Backbone returns the object but Backbone.history returns undefined.
What could be the cause of this?
Thanks
Do you have any routes on the controller? Backbone only creates the history once at least one route is specified.
More:
TypeError: Cannot call method 'start' of undefined**
Hmm, for some reason Backbone.history is undefined, and so there is no start method on it. It turns out that Backbone.js creates an instance of Backbone.History (upper case ‘H’) called Backbone.history (lower case ‘h’) once a controller has been created that has at least one route specified on it. This makes sense, as history management is only required if there are routes to respond to.
http://tinnedfruit.com/2011/04/26/testing-backbone-apps-with-jasmine-sinon-3.html
I hit the same error.
This happens when you do not make an instance of the router:
var routerInstance = new blogRouter();
If you're using CoffeeScript and your Router is defined using the CoffeeScript class keyword with a constructor method, double check that you invoke super in the definition of the constructor. This resolved the issue of Backbone.history being null for me.
class AppRouter extends Backbone.Router
constructor: (options) ->
super(options)
# other initialization code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With