Navigation Issue with Durandal

302 Views Asked by At

I'm using the hot towel template, and I'm trying to understand how to navigate to a different view via a javascript call. When my page loads, it looks like this:

enter image description here

Then, if I click any other button, then click the apps button again, I wrote some test code to just take the user to the ping page. This is in the apps view model:

function activate() {
    if (initialized) { router.navigateTo("#/ping"); return; }

    // more code here (doesn't get hit the second time through)
}

But what happens is the URL is correctly the ping URL, and the ping button is selected, but the actual content is still showing the applications:

enter image description here

If I want to navigate to another page without clicking in the navbar at the top, how should that be done?

1

There are 1 best solutions below

1
On BEST ANSWER

Your 'router.navigateTo('#/ping') is correct.

But when activate method is called, lots of heavy tasks are being done by durandal, it's too late for

your commanding, if you want to prevent opening a page and instead of that You'd like to go to

another page , then you can use 'CanActivate' method as following :

function canActivate() {
    if (initialized) { router.navigateTo("#/ping"); return false; 
                                         /* return false to prevent opening a page */ }
    else return true;
}

Also your application's performance will be boosted too

Good luck.