Subscribe to changes in window.location
CoffeeScript JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
package.json
pather.js

README.md

Pather.js

Subscribe to changes in window.location

Build Status

Disclaimer: This is work in progress

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

Examples

Simple

Pather.on("/foo/bar", function() {
  console.log("Enter /foo/bar");
})

window.history.pushState({}, null, "/foo/bar")

Named parameters (Sinatra/Backbone style)

Pather.on("/foo/:a/:b", function(a, b) {
  console.log("Enter /foo/"+a+"/"+b);
})

window.history.pushState({}, null, "/foo/bar/baz")

You can also match against the location hash:

Try in jsfiddle

Pather.on("/fruits/:fruit/#:bookmark", function(fruit, bookmark) {
  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"