Routing.js is a lightweight, client-side routing library that allows you to create "single page" applications using Hashbangs and/or HTML5 pushState.
- Lightweight
- Supports the HTML5 History API, the 'onhashchange' method, and graceful degredation
- Supports root routes, fallback methods, paramaterised routes, optional route components (dynamic routes), and Aspect Oriented Programming
- Well Tested (tests available in the
./tests
directory) - Compatible with all major browsers (Tested on Firefox 4+, Chrome 14+, Opera 11.1+, IE8+)
- Independant of all third party libraries, but plays nice with all of them
Routing.js is a fork of PathJS the primary differences are
- Internal logic for route-matching
- Parameters are returned as objects rather than the simple value from the URL
function clearPanel(){
// You can put some code in here to do fancy DOM transitions, such as fade-out or slide-in.
}
Routing.map("#/users")
.to(function(){
alert("Users!");
});
Routing.map("#/comments")
.before(clearPanel)
.to(function(){
alert("Comments!");
});
Routing.map("#/posts")
.before(clearPanel)
.to(function(){
alert("Posts!");
});
Routing.root("#/posts");
Routing.listen();
The Wiki details the objects, functions and properties which are exposed by Routing.js.
To run the tests, simply navigate to the ./tests
folder and open the HTML file in your browser. Please note that the HTML5 History API is not compatible with the
file://
protocol.
To make a pull request, please do the following:
- Mention what specific version of Routing.js you were using when you encountered the issue/added the feature. This can be accessed by doing
Routing.version
in a debugger console - Provide a pastie or gist that demonstrates the bug/feature
- Make sure you update the test suite with your changes. All tests must pass
- Make sure to update the minified version of the source
- Do not modify the
Routing.version
attribute. I will modify that manually when merging the request
This script is provided without warranty. As is, the script currently passes all its tests and so is believed to be fit for use. However, it is possible that the tests do not fulfil all possible scenarios and consequently further changes may be made which may break backwards compatibility. It should also be remembered that this script is not yet at version 1.
Copyright © 2014 Andrew Jameson, released under the MIT license.