Your javascript in the data-bind attribute, "click: gotoPage('mypage')", gets evaluated at binding time, i.e. "gotoPage('mypage')" gets executed at binding time, and the result is bound to the click event.
So you need to bind to a property, where that property points to the desired function.
In other words do this in your view:
<button data-bind="click: gotoMyPage">go somewhere</button>
and do something like this in your viewmodel:
define([
'durandal/app',
'knockout',
'plugins/router'],
function (app, ko, router) {
var vm = {
CurrentEntity: ko.observable(),
gotoMyPage: GoToPage
activate: activate
};
return vm;
function GoToPage() {
router.navigate('#mypage');
};
function activate() {
// activation code here, make sure no redirect code exists here
};
);
Part B
Your GoToPage routine CAN take a parameter, e.g.
function GoToPage(page) {
router.navigate(page.mypage);
};
View:
<table>
<tbody data-bind="foreach: listOfPages">
<tr>
<td data-bind="text: mypage, click: gotoMyPage"></td>
</tr>
</tbody>
</table>
(where listOfPages contains a list of page objects, and each page object has a mypage element).
More info here: Knockout documentation on foreach