4

I have a modular structure to my App meaning I have many config files with route definition in them. I am trying to use a resolver to check if the user is authenticated or not before I move them to the next route view.

right now I can reuse a function in the config as my resolve method i.e.

function resolverFunc(Auth, $state){
    if(!Auth.isLoggedIn()){
      $state.go('login');
   }
}

$stateProvider.state('state1', {
     url: "/myurl",
     resolver:{
         loggedIn: resolverFunc
    }
  }
)
.state('state2',{
    url: '/url2',
    resolver:{
        loggedIn: resolverFunc
    }
})

the problem is that I have to define the resolverfunc in every module. Because every module has it's own module.config() where the routes are defined for that module.

Is there a simpler solution. I hate to have to re-write this function in every config file for all the modules with routes

Subtubes
  • 15,851
  • 22
  • 70
  • 105
  • 1
    Before you'll get answer, this is how I use it: http://stackoverflow.com/a/26241415/1679310 - introduce one shared root state for all modules.. in a nutshell – Radim Köhler Feb 02 '15 at 07:03

0 Answers0