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