minimalistic hash-based router
Tiny (~1kb) static-routes no-frills hash-based router for single-page-apps.
NOTE: Route Links expected as "#/". hashes ("#") work as expected
Routes([routes = {}]).start();
routes{Object} - preloaded {route:function, ...} routes (optional)
addadds a route to the registryremovedeletes a route from the registryroutetriggers a routestartinitializes the router to watch for changes
Routes.params(qs)converts a query string into JSON
// routes.js
import Routes from 'dist/routes.min.js';
const routes = new Routes({
routes: {
"/": console.log("Home Page"),
"/one": console.log("One"),
"/two/:id": (vals, qs) => console.log(vals[0], qs),
"/three/:id/:greet": console.log,
"/four/?name=geoff": console.log,
}
}).start();or you can define your routes one at a time via
const routes = new Routes();
routes.add('/', function() {
console.log('yeah, we hit our route');
});
// call start last
routes.start();npm test
and lint via
npm run lint
- write tests
- params return as an array, would like this to be a key/value object that is merged with query string params
Please open an issue for support.
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines, they're minimalistic;)
MIT 2024 Geoff Doty