Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot call 'start' of undefined when starting backbone.js history.

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

like image 742
fancy Avatar asked Sep 08 '11 05:09

fancy


3 Answers

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

like image 145
wesbos Avatar answered Oct 17 '22 06:10

wesbos


I hit the same error.

This happens when you do not make an instance of the router:

var routerInstance = new blogRouter();
like image 10
chrisftw Avatar answered Oct 17 '22 07:10

chrisftw


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
like image 6
mgadda Avatar answered Oct 17 '22 06:10

mgadda