Skip to content

Instantly share code, notes, and snippets.

@nathanborror
Created September 17, 2009 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanborror/188346 to your computer and use it in GitHub Desktop.
Save nathanborror/188346 to your computer and use it in GitHub Desktop.
URL resolver
urlpatterns([
{'regex': /^\/(\w+)\/$/, 'view': View.timeline},
{'regex': /^\/(\w+)\/timeline\//, 'view': View.timeline},
{'regex': /^\/(\w+)\/notes\//, 'view': View.notes},
{'regex': /^\/(\w+)\/books\/$/, 'view': View.readerbooks},
{'regex': /^\/(\w+)\/contacts\//, 'view': View.contacts}
]);
function urlpatterns(obj) {
for (var i=0; i<obj.length; i++) {
var url = obj[i];
var path = window.location.pathname;
if (path.match(url['regex'])) {
url['view']();
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment