bike-lane v0.0.14
BikeLane
BikeLane is a client-side router.
- Stand-alone. Use with any other library or framework.
- No dependencies.
- Uses HTML5 history mode.
Installation
npm
$ npm install --save bike-lane
Router API
Router.constructor()
Create a router for your page:
var router = new Router()
BikeLane currently only supports using one router per page.
Router.addRoute(route, handler)
Add a route:
router.addRoute('/user', function() {
console.log('User route handler called.')
})
Routes can have named parameters:
router.addRoute('/user/:id', function(data) {
let userId = data.parameter('id')
console.log('User ID is', userId)
})
Use a wildcard at the end to match a group of routes:
/food/*
/user/:id/action/*
/food/*
will match /food/pizza
and /food/burger
. It will not match /food
.
The router will only match a single route and gives priority to routes registered first.
For example:
router.addRoute('/food/:type', handlerOne)
router.addRoute('/food/pizza', handlerTwo)
handlerTwo()
will never be called as the /food/:type
route was registered first.
Router.start() & Router.stop()
Router.start()
activates the router will trigger the handler for the current URL.
Router.stop()
stops the router.
Router.navigate(url)
Call navigate()
to change location. Internally, the router will update the window location using history.pushState()
.
Version
Version 0.0.14: Intitial release. Don't use this in projects yet.
Versioning
BikeLane will be maintained under the Semantic Versioning guidelines. Releases will be numbered with the following format:
<major>.<minor>.<patch>
- Incompatible API changes bump the major (and resets the minor and patch)
- New functionality introduced in a backwards-compatible manner will bump the minor.
- Backwards-compatible bug fixes will bump the patch.
For more information please visit http://semver.org/spec/v2.0.0.html.