:metal: KnockoutJS Goodies Monorepo
Idiomatically set child/nested routes
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
})