Skip to content

Instantly share code, notes, and snippets.

@mpolichette
Last active December 23, 2015 11:29
Show Gist options
  • Save mpolichette/6628746 to your computer and use it in GitHub Desktop.
Save mpolichette/6628746 to your computer and use it in GitHub Desktop.
Example route listener
App.module("BreadcrumbApp", function(BreadcrumbApp, App, Backbone, Marionette, $, _){
var API = {
showProject: function(id){
new BreadcrumbApp.Show.Controller({
/* Stuff */
});
},
showUser: function(id){
new BreadcrumbApp.Show.Controller({
/* Stuff */
});
}
};
// could be App.history or whatever
Backbone.history.on("route", function(router, routeName, args){
if(API[routeName]){
API[routeName].apply(API, args);
} else {
console.warn("Route not handled");
}
});
});
// In another file
App.module("ProjectApp", function(ProjectApp, App, Backbone, Marionette, $, _){
var API = {
showProject: function(id){
/* do stuff */
}
};
ProjectApp.Router = Marionette.AppRouter.extend({
appRoutes: {
"project/:id" : "showProject"
}
});
App.addInitializer(function(){
new ProjectApp.Router({
controller: API
})
});
});
// In yet another file
App.module("UserApp", function(UserApp, App, Backbone, Marionette, $, _){
var API = {
showUser: function(id){
/* do stuff */
}
};
UserApp.Router = Marionette.AppRouter.extend({
appRoutes: {
"user/:id" : "showUser"
}
});
App.addInitializer(function(){
new UserApp.Router({
controller: API
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment