Apress.js is a simple library for routing on client side in SPA projects.
Simplest usage exmaple of Apress can be found here.
$bower install apress --save
In HTML:
<script src="apress.js"></script>
and then in JS:
apress.addRoute(
'/hello/world', // route we're looking for, in this example it's http://mysite.com#!/hello/world
function(){ // listener that fires when the hash matches
//some action...
}
);
apress.hashTest(); // this forces the app to fire listener for
// the current route, useful for instance on app startup
apress.addRoute(route,callback)
- adding route, route can be string or regexp. It can also contain one of the two special characters - *
for wildcard (so everything will be matched in place of the asterix) or %
for 'pass whatever it matches as a callback argument'
apress.hashTest()
- manual hash checking
apress.setRoute(route)
- setting new route manually
apress.removeRoute(route)
- remove previously defined route
apress.getRoute()
- get actual route
apress.setErrorPage(function)
- set function which is trigger when the route don't match any of the registered patterns