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

10,375

Solution 1

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

Solution 2

I hit the same error.

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

var routerInstance = new blogRouter();

Solution 3

Make sure you include jQuery.js before underscore.js and backbone.js in HTML head.

Solution 4

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

Solution 5

I faced exact same issue for different reason, after spending couple of hours i realized that a method in my router "route" : function() is causing the issue, after i comment this unnecessary extra method, history.start() worked as expected.

Share:
10,375
fancy
Author by

fancy

Updated on June 04, 2022

Comments

  • fancy
    fancy almost 2 years

    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