angular / router

The Angular 1 Component Router
MIT License
665 stars 135 forks source link

Replacing routing config when role changes. #357

Open ajaxscape opened 9 years ago

ajaxscape commented 9 years ago

I really like the idea of specifying routes as components but I'm tearing my hair out trying to work out how to apply authentication. What I would really like to do is when a user changes their roles (log-in, log-out, log-in as someone else) I could really do with replacing the routing config by calling $router.config() with another set of routes that replace the previous. Is there any way to do this?

amritk commented 9 years ago

I think you can do something using the lifestyle components

http://www.sitepoint.com/introduction-futuristic-new-router-angularjs/#managing-the-lifecycle-of-components

this.canActivate = function(){
  var hasAccess =  userAccessInfo.hasAccessToSecondComponent;
  if(!hasAccess){
    $window.alert('You don\'t have access to this view. 
      Redirecting to previous view ...');
  }
  return hasAccess;
};

Not 100% sure since I haven't messed around with it too much myself yet

ajaxscape commented 9 years ago

I would rather I was able to display a 404 error page (with the url being the attempted page load) without it displaying the previous view ..... and what if someone is trying to deep-link to a view that exists but not for that user?