title: angularjs: conditional routing in app.config
body: <p>I'm facing an issue in angular.js ui-router and not able to sort it out .</p>
  
  <h3>Issue:</h3>
  
  <p>I want user to access all routes defined in config if the user is EnterpriseAdmin and restrict some routes if the user is Enterprise user.</p>
  
  <h3>Routes are defined in config:</h3>
  
  <pre><code> var adocsModule = angular.module('myApp', ['ngResource', 'ngRoute','ui.bootstrap','ui.router', 'ngAnimate']) 
  .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
     $stateProvider.state('Registration', {
          url: "/Registration",
          templateUrl: '/Scripts/App/Registration/Templates/registration.html', controller: 'CoursesController'
      })
      .state('Registration.Instructors', {
           url: "/Instructors",
           templateUrl: '/Scripts/App/Instructors/Templates/instructors.html', controller: 'InstructorController'
      })
      .state('Registration.Courses', {
           url: "/Courses",
           templateUrl: '/Scripts/App/Instructors/Templates/courses.html', controller: 'CoursesController'
      })
  </code></pre>
  
  <p>Can someone help me solve this issue because as per my understanding app.js is loaded before all controllers . Surely I can check in the controller if the user is either EnterpriseAdmin or Enterprise user but up to that time all routes are already configured and the user has access to them.</p>
  
  <p>Is there any way that I can do ajax call in the config block and then define a global variable and then by checking it i can configure some routes or not ?? </p>
  
  <p>Any help will be appreciated
  Regards</p>