@profiscience/knockout-contrib-router-plugins-children
TypeScript icon, indicating that this package has built-in type declarations

2.0.17 • Public • Published

router.plugins.children

Version Dependency Status Peer Dependency Status Dev Dependency Status Downloads

Idiomatically set child/nested routes

Usage

import {
  Route,
  childrenRoutePlugin
} from '@profiscience/knockout-contrib'

Route.usePlugin(childrenRoutePlugin)

new Route('/users', {
  children: [
    new Route('/', ...),
    new Route('/:id', ...),
    new Route('/:id/edit', ...)
  ]
})

Object-shorthand is supported, but it should only be used to migrate legacy routes as it requires casting as any (with TypeScript). This is due to the fact that in order to support object shorthand (which uses keys as the route names, meaning they are dynamic), and index signature must be added, and in doing so the strictness of the typechecking (and thus the usefulness) is greatly diminished when using the (preferred) route constructor syntax. But alas... here it is.

new Route('/users', {
  children: {
    '/': ...,
    '/:id': ...,
    '/:id/edit': ...
  } as any // <----- If you're using TS, you HAVE to do this, or it will not compile
})

Readme

Keywords

none

Package Sidebar

Install

npm i @profiscience/knockout-contrib-router-plugins-children

Weekly Downloads

0

Version

2.0.17

License

WTFPL

Unpacked Size

17.6 kB

Total Files

12

Last publish

Collaborators

  • dorgeron
  • barsh