Skip to content

Instantly share code, notes, and snippets.

@OndeVai
Created March 20, 2012 20:00
Show Gist options
  • Save OndeVai/2140686 to your computer and use it in GitHub Desktop.
Save OndeVai/2140686 to your computer and use it in GitHub Desktop.
Sammy Routing Skeleton
//all should be wrapped in jquery func
var my = my || {};
//routes setup
my.routes = (function () {
var hashBang = '#!/', //here could check if browser supports pushstate and avoid the hashbang
createRoute = function (route) {
return hashBang + route;
};
return {
createRoute: createRoute
};
})();
//sammy setup
my.sammyRouter = $.sammy('[jquery selector]', function () {
var saveContext = null;
this.get(my.routes.createStepRoute('route with params'), function (context) {
saveContext = context;
//can perform model updates & validation (KO)
//could redirect based on validation
});
this.after(function () {
//saveContext
//can perform after all routes exec
});
});
//start sammy
my.sammyRouter.run('initial route');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment