Front end router for single page applications
A dead simple router for Lokua.net, inspired by Page.js. Please note that this is still a <1 version.
npm i lokua.net.router --save
Router has two hard dependencies: lokua.net.bus, a super tiny message pattern, and lokua.net.route. If you would like to use either of those in your project you should install those as well, and use either the ES6 source, or the standalone dist/router.js build, which will not include those files. Otherwise, point to the bundled UMD version at dist/router.bundle.js.
const router = new Router({
// clicks on links with this class will add to history
// state without reloading the page and trigger a matching handler
link: '.a--route'
});
router
.route('/a*', handler)
.route('/b*', handler)
.route('/c*', handler)
.start(true); // dispatch on initial page load
function handler(route) {
// route={ path, params, query, queryString }
// replace a view or something...
}
router.replace(`${location.pathname}/c/foo`, { some: 'state' })
more examples to come...
To see Router in action, navigate to the project's root and run:
npm install -D
.
After installing, start the demo server by running npm run demo
,
then point your browser to http://localhost:3000
.
npm run build
# or
./bin/build
Testing is done with Jasmine standalone, included in test folder.
Run npm test
then navigate to http://localhost:3000
.