Component-based router for developing wicked awesome single-page apps with KnockoutJS.
Supports nested routing, read/write querystring param observables, read/write state observables
'use strict'
require('ko-component-router')
ko.components.register('app', {
viewModel: class App {
constructor() {
this.routes = {
'/': 'home',
'/user/:id': 'user'
}
}
},
template: `
<ko-component-router params="
routes: routes,
hashbang: false">
</ko-component-router>
`
})
ko.component.register('home', {
template: `<a href="/users/1234">Show user</a>`
})
ko.components.register('user', {
viewModel: class User {
constructor(ctx) {
// ctx.params
// ctx.query
// ctx.hash
//
// ...and more!
}
},
template: '<!-- ctx is also available as $router in the binding context -->'
})
ko.applyBindings()<body>
<app></app>
</body>Requires babel-polyfill for IE support