Last active
December 23, 2015 11:29
-
-
Save mpolichette/6628746 to your computer and use it in GitHub Desktop.
Example route listener
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
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