ko-component-router
v5.0.1
Published
Component-based routing for KnockoutJS
Downloads
85
Readme
ko-component-router
Super duper flexible component based router for developing wicked awesome single page apps with KnockoutJS.
Installation
$ yarn add ko-component-router
...or...
$ npm install -S ko-component-router
Basic Usage
import ko from 'knockout'
import 'ko-component-router'
ko.components.register('app', {
viewModel: class App {
constructor() {
this.routes = {
'/': 'home',
'/user/:id': 'user'
}
}
},
template: `
<ko-component-router params="routes: routes"></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
//
// ...and more!
}
}
})
ko.applyBindings()