lokua.net.router v0.13.0
lokua.net.router
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.
Installation
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.
Setup
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...
}
Replacing routes manually without loading the page
router.replace(`${location.pathname}/c/foo`, { some: 'state' })
more examples to come...
Demo
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
.
Dev
Build
npm run build
# or
./bin/build
Test
Testing is done with Jasmine standalone, included in test folder.
Run npm test
then navigate to http://localhost:3000
.