pather

A window.location listener with added relish

Pather.js

Drop-dead simple window.location.pathname listener

Works in browsers supporting the HTML5 History API, for older browsers, a polyfill like devote/HTML5-History-API is required.

Examples

Path.on("/foo/bar", function() {
  console.log("Enter /foo/bar");
})
 
window.history.pushState({}, null, "/foo/bar")

View this example in jsfiddle

Path.on("/foo/:a/:b", function(ab) {
  console.log("Enter /foo/"+a+"/"+b);
})
 
window.history.pushState({}, null, "/foo/bar/baz")