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

1
  • 1
    Before you'll get answer, this is how I use it: stackoverflow.com/a/26241415/1679310 - introduce one shared root state for all modules.. in a nutshell Commented Feb 2, 2015 at 7:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.