Skip to content

Instantly share code, notes, and snippets.

@piatra
Created August 24, 2014 20:19
Show Gist options
  • Save piatra/360207765e2f4d111699 to your computer and use it in GitHub Desktop.
Save piatra/360207765e2f4d111699 to your computer and use it in GitHub Desktop.
[Backbone router] Child route to trigger parent route action as well
(function() {
"use strict";
var MyRouter = Backbone.Router.extend({
routes: {
"/" : "home",
"user/:username" : "profilePage",
"user/:username/following": "following",
"user/:username/followers": "followers"
},
home: function() {
console.log("welcome to the homepage");
},
profilePage: function() {
console.log("this is your profile");
},
following: function() {
console.log("these are the users you are following");
},
followers: function() {
console.log("these are your followers");
}
});
var appRouter = new MyRouter();
appRouter.on("route:following route:followers", function() {
console.log("Trigger the /user route as well");
});
Backbone.history.start();
})();
@piatra
Copy link
Author

piatra commented Aug 24, 2014

There are other solutions to this problem on stackoverflow but most people recommend using backbone.marionette which fixes a lot of "issues" concerning view handling in Backbone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment