@profiscience/knockout-contrib-router-plugins-children
v2.0.17
Published
[![Version][npm-version-shield]][npm] [![Dependency Status][david-dm-shield]][david-dm] [![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer] [![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev] [![Downloads][npm-stats-shield]][npm-sta
Downloads
36
Readme
router.plugins.children
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
})