History.start () function does not work in the spine

I'm a newbie trying to use Routers on the backbone but my method Backbone.history.start()

doesn't work. It gives me below error

Uncaught TypeError: Cannot call method 'start' of undefined 

      

Here is my code

(function ($) {
window.App = {
    Models: {},
    Collections: {},
    Views: {},
    Router: {}
};

window.Template = function (id) {
    return _.template( $('#' + id).html() );
};

App.Router = Backbone.Router.extend({
    routers: {
        '': 'index'
    },

    index: function () {
        console.log('index page');
    }
});

var r = new App.Router;
Backbone.history.start();
})(jQuery);

      

How do I remove this error?

+3


source to share


2 answers


This is because your router does not routes

. You have routers

and it is not the same :)



+3


source


Change routers to routes

App.Router = Backbone.Router.extend({
    routes: {
        '': 'index'
    },

    index: function () {
        console.log('index page');
    }
});

      



Now create a routers object and start the basic story.

app = App.Router();
Backbone.history.start();

      

+1


source







All Articles