/ko-component-router

:station: Component based router for developing wicked awesome apps with Knockout

Primary LanguageJavaScriptDo What The F*ck You Want To Public LicenseWTFPL

ko-component-router

NPM Version WTFPL Travis Coverage Status Dependency Status Peer Dependency Status NPM Downloads Gitter

Super duper flexible component based router for developing wicked awesome single page apps with KnockoutJS.

Migrating from 3.x to 4.x.

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()

More