【发布时间】:2014-12-27 18:37:29
【问题描述】:
我正在尝试在我的 Angular 应用程序上实现授权,当路由更改时,我想检查该路由是否已为用户授权。我尝试使用$routeChangeStart,但它并不能阻止该事件。
我当前的代码:
$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();
}
}
});
在我的next 对象中,我得到了在我的$routeProvider 中设置的 route_object
var routes = object;
app.config(function($routeProvider) {
$routeProvider.when(url, {
templateUrl: "/users.html",
route_object: routes,
});
});
routes 是在我的函数中形成的一个对象,但是当我使用 $locationChangeStart 时,我只是获取下一页和上一页的 url,
如何获取整个路由对象??
【问题讨论】:
标签: angularjs authorization angularjs-routing