highway
A simple and multi-purpose router with history management.
Installation
npm install highway
How to use
Require and initialize highway:
var Highway = highway = ;
Add a route:
var handle = highway;
Remove a route :
highway;
Navigate to a route:
// this will call the handler that's defined for route with all of the following paramshighway;
Watch for route changes:
var handle = highway;
Stop watching for route changes:
highway;
Navigate in the history:
// Go back in the history, we reload the previous route with the same params.
highway.back();
// Go forward
highway.forward();
// Go back 3 times
highway.go(-3);
// Go forward 2 times
highway.get(-2);
Increase the saved history (10 by default):
// Save the last 100 routeshighway;
clear history
highway;
How to extend?
This a very simple router. You can build on top it if you want it to be URL based for instance:
{ var highway = ; { return ... } { return ... } this { var route = params = ; highwaynavigate; }; ...}
You could also bind it to hashchange:
{ var highway = ; { return ... } { return ... } window; ...}
CHANGELOG
0.0.5 - 5 MAR 2016
- Can now navigate to non-registered routes. They will be saved in the history and trigger the watch() callback.
- API clean-up with private functions not revealed in the public API anymore.
- Add specs for setMaxHistory
0.0.4 - 7 AUG 2015
- Rename constructor to HighwayConstructor
- Rewrote tests to make them easier to read
0.0.3 - 12 APR 2015
- Update to watch-notify 0.0.3
LICENSE
MIT