Created
March 24, 2015 16:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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