Dynamic router in Durandal 2.0
The router configuratin is in the shell.js file. I need to make this router dynamically managable. To do so, I have used ajax.
The change is in the active method in shell.js file.
activate: function () {
var routes = [];
$.ajax({
url: "/Route/Get",
async: false,
dataType : 'json'
}).done(function (response) {
routes = response;
});
router.map(routes).buildNavigationModel();
return router.activate();
}
The server code is as below.
public JsonResult Get()
{
List route = new List()
{
new Route(){ route = "" ,title = "Welcome", moduleId = "viewmodels/welcome", nav= true },
new Route(){ route = "flickr" , moduleId = "viewmodels/flickr" , nav= true }
};
return Json(route , JsonRequestBehavior.AllowGet);
}
Leave a Comment