import ko from 'knockout'
import { Router } from '@profiscience/knockout-contrib-router'
import template from './index.html'
function createOuterTemplate(foo) {
return `
${foo}
These begin with '/', so they route using the current (containing) router
/foo
/bar
This begins with './', so it is routed using the child (adjacent) router
./baz
This begins with '//', so it is routed using the root router
//${foo}/qux
`
}
function createInnerTemplate(foo) {
return `
${foo}
These begin with '/', so they route using the current (containing) router
/baz
/qux
`
}
ko.components.register('empty', { template: '' })
ko.components.register('foo', { template: createOuterTemplate('foo') })
ko.components.register('bar', { template: createOuterTemplate('bar') })
ko.components.register('baz', { template: createInnerTemplate('baz') })
ko.components.register('qux', { template: createInnerTemplate('qux') })
Router.useRoutes({
'/': 'empty',
'/foo': [
'foo',
{
'/': 'empty',
'/baz': 'baz',
'/qux': 'qux',
},
],
'/bar': [
'bar',
{
'/': 'empty',
'/baz': 'baz',
'/qux': 'qux',
},
],
})
ko.components.register('path-binding', { template })