jsrouter
jsrouter
is a minimal client side router based on window.location.hash
. It utilizes route-recognizer to match routes and leans on this library for the API as well. For this reason, you will notice that the API is very similar to Ember's router, though more minimal and with less lifecycle states.
Installation
npm
npm install --save jsrouter
cdn
While the npm
package is recommended for production usage, if you just want to drop a <script>
tag on your page you can also use the UMD/global build hosted on unpkg
.
Usage
This is to provide a good idea of what the API looks like and what jsrouter
can do. Check out the documentation for more details as well as an in depth breakdown of the API.
Create the router
; // create a new routervar router = ;
Define routes
// define routesrouter;
Define handlers
// define handlersrouter;// etc...
Using the router
// using the routerrouter;router; // optionally takes data to store in window.history.replaceStaterouter; router; // window.history.back();router; // window.history.forward();
Configuration
The router takes an optional object as an argument that allows it to override default configuration and customize the behavior of the router.
var router = { router; } { // do not change routes if this returns false } // ... // etc.;