Last active
December 22, 2015 16:09
-
-
Save ruzz311/6497572 to your computer and use it in GitHub Desktop.
my favorite router so far
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
define([ | |
// Application. | |
'app', | |
'modules/section' | |
], function (app, Section) { | |
var Router = Backbone.Router.extend({ | |
routes : { | |
'' : 'index', | |
'*route' : 'allRoutes' | |
}, | |
initialize : function () { app.useLayout(); }, | |
// Whatever you want the 'index' to be. | |
index : function () { Section.change('facts'); }, | |
// Routes assume a corresponding template with the same name. | |
// rarr because we like jurassic park. | |
allRoutes : function (route) { | |
var rarr = route.split('/'); | |
if (rarr.length > 1) { | |
Section.change(rarr[0], rarr[1]); | |
} else { | |
Section.change(rarr[0]); | |
} | |
} | |
}); | |
return Router; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment