How can I dynamically change the visibility of a Durandal Route? -


i have durandal routes configured below.

var routes = [  ....... more routes here..... {     url: 'login',     moduleid: 'viewmodels/login',     name: 'log in',     visible: true,     caption: 'log in' }, {     url: 'logout',     moduleid: 'viewmodels/logout',     name: 'log out',     visible: false,     caption: 'log out' }, {     url: 'register',     moduleid: 'viewmodels/register',     name: 'register',     visible: false,     caption: 'register' }]; 

and working expected. able activate logout route in navigation when log in , log in button become invisible. have tried following code , despite not throwing errors not change visibility of in interface.

var isloggedin = ko.observable(false); isloggedin.subscribe(function (newvalue) {     var routes = router.allroutes();     if (newvalue == true) {         (var k = 0; k < routes.length; k++) {             if (routes[k].url == 'logout') {                 routes[k].visible = true;             }             if (routes[k].url == 'login') {                 routes[k].visible = false;             }         }      } else {          (var = 0; < routes.length; i++) {              if (routes[i].url == 'logout') {                  routes[i].visible = false;               }                         if (routes[i].url == 'login') {                   routes[i].visible = true;               }          }      } }); 

i believe doesn't work because visible not observable, isactive computed no write capability not work either. how can dynamically change visibility of routes in nav menu?

here ended doing.

//ajax call log user in .done(function (recieveddata) {     if (recieveddata == true) {         router.deactivate();         return router.map(config.routesloggedin);     } else {         router.deactivate();         return router.map(config.routes);     } }).done(function() {     router.activate('frames');     return router.navigateto('#/frames'); }); 

essentially created 2 routing profiles in config object. 1 logged in , 1 not. there 1 caveat. router.deactivate() method new method , not in nuget package yet. copied code of new router master branch of github repository durandal. there discussion on new function on durandal user group. security reasons might feed logged in routes server. time being should work fine.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -