Reputation: 2622
Using durandal 2.1.0 on an ASP.Net MVC project. When a view is accessed I use the canActivate function to indicate whether they can access that view like so:
self.canActivate = function () {
return http.ajaxRequest("get", "/api/route/hasaccesstoroute?route=viewname")
.done(function (result) {
if (!result) {
app.showMessage("You do not have permissions to access this area!");
}
});
};
This works well but what I need to do for one view is to redirect to another view and having trouble doing so. Can anyone help how to change accordingly? I tried navigateTo but said this was not a valid function.
Upvotes: 0
Views: 124
Reputation: 2622
I figured this out and have left the question on should anyone else need to do this:
return http.ajaxRequest("get", "/api/route/hasaccesstoroute?route=viewname").then(function (response) {
if (response == true) {
return true;
}
else {
return { redirect: "#/viewname" };
}
});
Upvotes: 2