pather

A window.location listener with added relish

Pather.js

Subscribe to changes in window.location

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

Examples

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

Try in jsfiddle

Pather.on("/fruits/:fruit/#:bookmark", function(fruitbookmark) {
  console.log('Now display the "%s" section of the page about the "%s"', bookmark, fruit);
});
 
window.history.pushState({}, null, "/fruits/banana/")
window.location.hash = "nutrition_facts"