I am trying to implement Authorization on my angular application, when a route is changed I want to check whether the route is authorized for user or not. I tried with $routeChangeStart
but it does not prevents the event.
My current code:
$scope.$on('$routeChangeStart', function(event, next, current) {
if(current_user.is_logged_in){
var route_object = next.route_object;
if(!(route_object.route_roles)){
event.preventDefault();
}
}
});
Here in my next
object I am getting route_object which is set in my $routeProvider
var routes = object;
app.config(function($routeProvider) {
$routeProvider.when(url, {
templateUrl: "/users.html",
route_object: routes,
});
});
routes
is an object which is formed in my function, but when I use $locationChangeStart
I am just getting url's of next and previous page,
How do I get the entire route object??
$location.$$path
returns/users
but inside my route I have URL as/users/:id?
Because of which I am getting an error. – Yorke