I have a backbone marionette application with requirejs for loading module. Everything else is working just fine as expected. Until I put router in it. The router and controller binding does not seem to work. When I go to a route from address bar: in this case homedomain#edit/id
, the router is rerouted to home page. I am taking reference of Marionette a Gentle Introduction By David Sulc
for most of my code.
'use strict';
define([
'app',
'email_templates',
'email_list_controller'
], function(App) {
App.module('Email', function(Email, App, Backbone, Marionette) {
Email.Router = Marionette.AppRouter.extend({
appRoutes: {
'edit/:id' : 'editEmails',
'': 'listEmails'
}
});
var API = {
listEmails: function() {
require(['email_list_controller'], function(controller) {
App.navigate('/');
controller.list();
});
},
editEmails: function(item){
alert(item); //initial debugging point. this line is referenced in description below.
require(['email_edit_controller'], function(controller){
var id = typeof item === "string" ? item : item.id;
App.navigate('edit/'+id);
controller.editor(item);
});
}
};
Email.on('start', function() {
new Email.Router({
controller: API,
});
});
});
return App.Email;
});
From my understanding so far when I navigate to a route: #edit/<someRandomId>
the <someRandomId>
should be alerted on the screen. The exact line has been referenced. This is just my approach to see if the router is working. But in fact the whole Email.Router
is not working.