Pure JavaScript HTML5 router
Lightweight and fast router based on HTML5 history.
Why native history instead of location.hash
- html5 history API is more powerful (local state, previous state)
- Forward - backward statefull navigation out of the box
- The history API is a robust system that is actually designed to do that job (hash it is anchor to id actually)
- No server-side hacks for remove # (hash) from URL
- Easy and clean code
Installation
npm i html5-history-router
Changelog
Examples
Configure route map
; // Init router = ; // Add route change callback to router instance router; // Add callbacks chain to router router...
Route params parser
... router; router;
Route regexp match
... router; router;
Other callbacks
... router; router;
Routes change
... router; router;router; // go back // change route with staterouter; // after external route change you need call applyState// history.pushState(state, title, url);// router.applyState();// then router will try match current location to defined routes
Promise resolve
... router // Resolve route only when authorized ;
Custom State
;;;router.pushState'/product/23', state;
License
MIT