http://visionmedia.github.com/page.js/
Explicit paths, optional/required parameters, wildcard, regexp
"/user/"
"/user/:id"
"/user/:id/edit"
"/user/:id/:revision?"
"/download/(*)"
/^post\/\d{4}\/\d{2}\/\d{2}/
Opt out. No fallback for unsupported browsers.
page.start({
popstate : false,
click : false
});
May need some polyfill as it tries to use history.pushState even if it doesn't exist.
Shared context between callbacks.
page('/photos/:id', load, show);
function load(ctx, next) {
$.getJSON('/photos/' + ctx.params.id + '.json', function(data){
ctx.photo = data;
next();
});
}
function show(ctx) {
$('img').attr('src', ctx.photo.url);
}
page('*', all);
page('/help/', help);
function all(ctx, next) {
$.publish("new-page");
next();
}
function help(ctx) {
$('title').text('Help');
}
http://millermedeiros.github.com/crossroads.js/
Explicit paths, optional/required parameters, wildcard, regexp
"/user/"
"/user/{id}"
"/user/{id}/edit"
"/user/{id}/:revision:"
"/download/:*:"
/^post\/\d{4}\/\d{2}\/\d{2}/
None. Would need to hook up seperately if desired.
Very verbose. Need to create route then bind to route separately.
var sectionRoute = crossroads.addRoute('/{section}/{id}');
function onSectionMatch(section, id){
console.log(section +' - '+ id);
}
sectionRoute.matched.add(onSectionMatch);
Requires event library JS-Signals http://millermedeiros.github.com/js-signals/
var route = crossroads.addRoute('/{section}/{id}');
route.rules = {
section : ['posts', 'photos'],
id : function (value, request, values) {
if (+value < 100) {
return true;
}
return false;
}
}