Skip to content

Instantly share code, notes, and snippets.

@wallynm
Created March 24, 2015 16:41
Show Gist options
  • Save wallynm/0adcc6374ece2e49ae73 to your computer and use it in GitHub Desktop.
Save wallynm/0adcc6374ece2e49ae73 to your computer and use it in GitHub Desktop.
The base router start the History management for the url controlling, when user access template/ it access method invokeTemplate, as i'm using requireJS to take care of dependencies of my project i load the needed subrouter and when my subrouter get's loaded it's take care of the new routes.
mainRouter = Backbone.Router.extend({
routes : {
"templates/*subroute" : "invokeTemplates",
},
invokeTemplates: function()
{
console.log('>>>>> invokeTemplates');
require(['templateRouter'], function () {
App.Routers.Templates = new App.Routers.Templates("templates/");
});
}
});
// Configura o router
App.mainRouter = new mainRouter();
define(function () {
App.Routers.Templates = Backbone.SubRoute.extend({
routes: {
"" : "index",
"insert" : "insertTemplate",
"update/:id" : "updateTemplate",
},
index : function ()
{
console.log('Templates show');
require(['frontend/modules/templates/views/grid'] , function (templates) {
App.mainRegion.show(new templates);
});
},
insertTemplate : function ()
{
console.log('CREATE >>>>> TEMPLATE')
require(['frontend/modules/templates/views/list'] , function (templates) {
App.mainRegion.show(new templates);
});
},
updateTemplate: function (id)
{
console.log('EDIT >>>>> TEMPLATE ' + id)
require(['frontend/modules/templates/views/list'] , function (templates) {
App.mainRegion.show(new templates(id));
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment