Skip to content

Instantly share code, notes, and snippets.

@wolfgang42
Created May 17, 2016 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfgang42/1468176b83e73d1d8cca2d023ab4bb84 to your computer and use it in GitHub Desktop.
Save wolfgang42/1468176b83e73d1d8cca2d023ab4bb84 to your computer and use it in GitHub Desktop.
ko-component-router path binding test case

Test case to reproduce an issue with ko-component-router with hashbang:false (path bindings don't bind right when prefixed with ./)

To set up:

npm install
node_modules/.bin/webpack testcase.js bundle.js
node_modules/.bin/http-server

Then visit http://localhost:8080/#!/

<!doctype html>
<app></app>
<script src="/bundle.js"></script>
{
"dependencies": {
"http-server": "^0.9.0",
"knockout": "^3.4.0",
"ko-component-router": "^3.7.18",
"webpack": "^1.13.0"
}
}
'use strict'
require('ko-component-router')
var ko = require('knockout')
ko.components.register('app', {
viewModel: class App {
constructor() {
this.routes = {
'/': 'home',
'/user/:id': 'user'
}
}
},
template: `
<ko-component-router params="
routes: routes,
base: '',
hashbang: true">
</ko-component-router>
`
})
ko.components.register('home', {
template: `<a href="/user/1234">Show user</a>`
})
ko.components.register('user', {
viewModel: class User {
constructor(ctx) {
this.nextUser = ko.pureComputed(()=>parseInt(ctx.params.id())+1)
}
},
template: 'User: <!-- ko text: $router.params.id --><!-- /ko -->; next user: <a data-bind="path: \'./\'+nextUser(), text:nextUser()"></a>'
})
ko.applyBindings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment