Search code examples
backbone.jshistory

Backbone history do not start


i'm quite a newbie on Backbone, and this is driving me crazy: I'm using backbone and Marionette. Here is some code sample to begin :

var Backbone    = require('backbone'),
    Marionette  = require('backbone.marionette'),
    FastClick   = require('fastclick');

var MainModule      = require('./modules/main'),
    HomeModule      = require('./modules/home');

var app = new Marionette.Application();

app.vent.on('ready', function(e) {
    Backbone.history.start({
        pushState: true, // Use HTML5 history if available
        hashChange: false, // or refresh pages if it isnt supported natively
        root: '/',
    })
});

and in my /module/home/index.js :

module.exports = function HomeModule(Module, App, Backbone, Marionette, $, _) {

// Register Sub modules
App.module('Home', LayoutModule);
App.module('Home', WallModule);

Module.Router = Marionette.AppRouter.extend({
    appRoutes: {
        '/': 'home',
        'social-wall': 'socialwall'
    }
});

var controller = {
    home: function() {
        App.mainRegion.show(new Module.Layout());
    },

    socialwall: function() {
        controller.home();
        App.mainRegion.currentView.scrollToSocialWall();
    }
};

App.addInitializer(function() {
    new Module.Router({ controller: controller });
});
};

The problem is that Backbone.history.start do not trigger anything. If i understand the code correctly, the history.start() should find the '/' route in the HomeModule and trigger the associated function... Am I wrong?? Why is this not working?????

In advance, thanks


Solution

  • found it! as i said in the comment, it was a deployment error. The error was a bad package.json file on a npm install. Tip to front-devs : when u're making a npm package to install and deploy a Marionette project, be sure to include Backbone first, and with an explicit version... including only Marionette will cause npm to install Backbone twice (on project root and in marionette modules), and this is a source of big troubles...