Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created May 25, 2012 03:18
Show Gist options
  • Save edwardhotchkiss/2785552 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/2785552 to your computer and use it in GitHub Desktop.
Angular.js Routing Like a Boss (blog)
$route.when('/some/route', {
template : 'partials/some/route.html',
controller : SomeRouteController
});
/**
* @class app
* @returns {Object}
*/
var app = Object.create({
get : function(route, fn) {
var response = Object.create({
render : function(partial, controller) {
if (arguments.length === 2) {
var routeObj = Object.create({
reloadOnSearch : true,
template : partial,
controller : controller
});
} else if (arguments.length === 1) {
var routeObj = Object.create({
reloadOnSearch : true,
controller : controller
});
};
/**
* Check for trailing slashes:
* /my/route/
* /my/route
* ^ both matched
*/
$route.routes[route] = routeObj;
$route.routes[route + '/'] = routeObj;
}
});
fn.apply(this, [response]);
}
});
/* EOF */
app.get('/some/route', function(response) {
response.render('partials/some/route.html', SomeRouteController);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment