You could have a base state that controls which state to load, and you could simply have the child stated of that base state not have urls:
.state('home', {
url: "/home",
templateUrl: "....",
controller: function($scope,$state,authSvc) {
if(authSvc.userIsLoggedIn()){
$state.go('home.loggedin')
}else{
$state.go('home.public')
}
}
})
.state('home.public', {
url: "",
templateUrl: "....",
controller: function($scope) {
...........
}
})
.state('home.loggedin', {
url: "",
templateUrl: "....",
controller: function($scope) {
...........
}
})
Now in the controller of your base state (home
) you can check if the user is logged in or not, and use $state.go()
to load an appropriate state.
EDIT
As promised, a working plunk.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…