Created
August 24, 2014 20:19
-
-
Save piatra/360207765e2f4d111699 to your computer and use it in GitHub Desktop.
[Backbone router] Child route to trigger parent route action as well
This file contains hidden or 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
(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(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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