npm install mini-routerbower install mini-router
dist/click-interceptor.js- ClickInterceptor (standalone library, exported as global var)
dist/mini-router.core.js- Router without ClickInterceptor (standalone library)
dist/mini-router.js- Router + ClickInterceptor (standalone library)
router.js- CommonJS module (use with webpack or browserify)
ClickInterceptor.js- CommonJS module
var router =html5: true // default true if browser supports itbase: '' // optional base url (gets stripped away when routing)routes: '/some/route': callback // optional routesclickInterceptor: ClickInterceptor // override or set the ClickInterceptor// Define and handle route. You can use :named parameters.router;// Note: If you define multiple routes with the same name, only the latest callback is called!// Manually set location and fire route handlerrouter// Normalize URL;// - remove domain name.router // /some/path// - remove ending slashrouter // /some/path// - add prepending slashrouter // /some/path// You can also only use the click interceptor.// It translates link-clicks to hash-changes or html5 popState();
It seems that you only listen to history events. There is no event fired when the user navigates to a new location.
So we have to intercept click events. However, no micro router library has this functionality.
So I wrote this one!
- 0.5.0: Bugfix
- 0.4.0: Fixed ClickInterceptor bug with HTML5 (there is no
onpushstatelistener, so explicitly call
- 0.3.0: Fixed some versioning issues with NPM and Bower
- 0.2.0: Split Router into Router + ClickInterceptor. Some minor improvements.
- 0.1.0: Initial release
Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.
© 2014 - Mark Marijnissen