kris kaman
kris kaman

Reputation: 101

Marionette Routes/Initial configuration

I have my application set up in the following way. It does not allow me to trigger any "java-script routes"- after loading the page-- after I navigate to this page with a sub-domain extension to the url I enter.

//Create App
App = new Backbone.Marionette.Application();

//APP Regions
App.addRegions({
    displayRegion: "#displayRegion"
});

//Routing controller
someController = {
    usersarea: function () {
        App.displayRegion.show(userList_ITEM);
        alert('Users');
    },
    login: function () {
        App.displayRegion.show(login_view);
        alert('Login View');
    }
};


//Router
MyRouter = new Marionette.AppRouter({
    controller: someController,

    appRoutes: {
        "users": "usersarea",
        "login": "login",
    }

});//MyRouter


// Application Views

userList_ITEM_proto = Backbone.Marionette.ItemView.extend({
    template: "#userList_ITEM"
});


login_view_proto = Backbone.Marionette.ItemView.extend({
    template: "#login_view"
});


//Before STARTS
App.on('initialize:before', function () {
    if (!Backbone.History.started) Backbone.history.start();
    alert('It works');
    login_view = new login_view_proto;
    userList_ITEM = new userList_ITEM_proto;

});

//After START
App.on('initialize:after', function (options) {
    console.log('Initialization Finished');
});


//At Start
App.on('start', function (options) {
    alert('It works');
});

App.start();

Upvotes: 0

Views: 168

Answers (1)

pdoherty926
pdoherty926

Reputation: 10349

You're trying to use view instances in someController before you've instantiated them.

http://jsfiddle.net/ddL4n/28/

You have a number of dependency issues in this script and should consider using Marionette's modules or Require.js to manage them.

Upvotes: 1

Related Questions