2

Well I am trying to set the ui-router's abstract property to true dynamically, so that I can avoid unauthorized access by the user to that route. I could only think of that way to achieve that goal. Here's the demo route.

.state('project', {
    abstract: {{value}},
    url: '/users',
    templateUrl: 'views/configuration/index.html',
    },


I want that once the angular app loads, all such routes becomes abstract-true whose access should be denied to the user. Please help me out in achieving this task and learning something new.

Steve
  • 522
  • 3
  • 12
  • 28

1 Answers1

0

What you need is dynamic state load by using $urlRouter.sync():

$urlRouter.sync();
$urlRouter.listen();

I think this example in Plunker will help you to sort things out


var $stateProviderRef = null;

 // some value = {/* ... */}

 var getExistingState = $state.get(value.name)

  var state = {
     "url": value.url,
     "parent": value.parent,
     "abstract": value.abstract,
     "views": {}
   };

   angular.forEach(value.views, function(view) {
     state.views[view.name] = {
       templateUrl: view.templateUrl,
     };
   });

   $stateProviderRef.state(value.name, state);
 });        

 $urlRouter.sync();
 $urlRouter.listen();

Took demo from here

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
  • Thank you sir, but I had already seen this option, but couldn't satisfy my need as my routes contain different resolve properties. They all don't have the same format. – Steve May 27 '18 at 07:03