@mightylittle/router
v0.2.0
Published
Simple, regex-based URL dispatcher
Downloads
3
Readme
@mightylittle/router
Simple regex-based URL dispatcher for browser apps
This router is suitable for running in the main window or in a web worker.
There is no built-in integration with pushState or any other DOM API, so you are expected to write your own code to call the dispatch method. See the demo subdirectory for an example SPA.
Usage
JavaScript example:
const router = new Router({
notFound: () => {
console.log("404");
},
routes: {
"/": () => {
console.log("base route");
},
"/widgets/:widget": (context) => {
console.log("widgetId", context.binding.widget); // => xyz
console.log("url", context.url); // => http://www.example.net/widgets/xyz?hello=world
console.log("data", context.data); // => {foo: "bar"}
}
}
});
router.dispatch(new URL("http://www.example.net/widgets/xyz?hello=world"), {foo: "bar"});Installation
npm installDevelopment
Build:
npm run buildRun tests:
npm run testBuild docs:
npm run typedocAuthor
- John Newton
Copyright
- John Newton
License
Apache-2.0
