knockout-contrib

:metal: KnockoutJS Goodies Monorepo

View the Project on GitHub Profiscience/knockout-contrib

Router

ES2015

import { Router } from '@profiscience/knockout-contrib'

CommonJS

const { Router } = require('@profiscience/knockout-contrib')

Browser Globals

const { Router } = ko.router

API

Instance

router.ctx

Current router context object

router.initialized

Promise that returns after this router is initialized

router.depth

Depth of this router; accessor for router.ctx.$parents.length

router.isNavigating()

Observable value that is true if router is navigating

router.isRoot

Is the root router

router.update(path, [push = true], [options = { push: true, force: false, with: {} }])

Routes to path; adds history state entry if push === true

Second argument can be a boolean push, or an options object:

Option Description Default
push push history state entry true
force force reload of same route false
with object to extend context with {}

Static

Router.get(index)

Return router at the given depth, beginning at 0

Router.head

Top-most router

Router.initialized

Alias for Router.head.initialized

Router.isNavigating()

Observable value which is true if any routers are navigating, including nested routers

Router.setConfig({ base = ‘’, hashbang = false, activePathCSSClass = ‘active-path’ })

Sets router configuration. See Basic Usage for more.

Router.use(…fns)

Registers app middleware

Router.usePlugin(…fns) [deprecated]

Registers plugin. Use Route.usePlugin instead.

Plugins must be registered before routes

Router.useRoutes(routes)

Registers routes

NOTE: setConfig and the use methods may be chained, e.g.

Router.setConfig(routerConfig)

  .use(someMiddleware)
  .use(anotherMiddleware)

  .usePlugin(somePlugin)
  .useRoutes(homeRoutes)
  .useRoutes(profileRoutes)

Router.update(path, [push = true], [options = { push: true, force: false, with: {} }])

Convenience function for Router.get(0).update(...)


Back