I get the error "Backbone.history is already running" in my Backbone.js application. Here is my code.
(function ($) { // model for each article var Article = Backbone.Model.extend({}); // collection for articles var ArticleCollection = Backbone.Collection.extend({ model: Article }); // view for index page var MainView = Backbone.View.extend({ el: $('#wrapper'), render: function (){ var template = Handlebars.compile($("#main_hb").html()); $(this.el).find('#main_content').html(template); return this; } }); // view for listing blog articles var ArticleListView = Backbone.View.extend({ el: $('#wrapper'), render: function(){ var js = this.model.toJSON(); var template = Handlebars.compile($("#articles_hb").html()); $(this.el).find('#main_content').html(template({articles: js})); return this; } }); // main app var ArticleApp = Backbone.Router.extend({ // setup routes routes: { "" : "index", "blog" : "blog" }, index: function(){ var main = new MainView({}); main.render(); return this; }, blog: function(){ $.ajax({ url: 'blogs/articles', dataType: 'json', data: {}, success: function(data) { var articles = new ArticleCollection(data); var view = new ArticleListView({model: articles}); view.render(); } }); return this; } }); // let start the app! articleApp = new ArticleApp(); Backbone.history.start(); })(jQuery);
It looks like the application is working fine. But this error in Chrome is mysterious.
ericbae
source share