Skip to content

Instantly share code, notes, and snippets.

@ruzz311
Last active December 22, 2015 16:09
Show Gist options
  • Save ruzz311/6497572 to your computer and use it in GitHub Desktop.
Save ruzz311/6497572 to your computer and use it in GitHub Desktop.
my favorite router so far
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