-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Milestone
Description
Given the following states:
$stateProvider.state('account', {
url: "/account",
templateUrl: 'app/account/account.html',
controller: 'AccountCtrl',
data : {
access : "EVERYBODY"
}
});
$stateProvider.state('contacts', {
url: "/contacts",
templateUrl: 'app/contacts/contacts.html',
controller: 'ContactsCtrl',
data : {
access : "LOGGED_IN"
}
});
I'm trying to prevent anonymous users from visiting any LOGGED_IN
states. So I'm setting this up in the main application controller:
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
if ( toState && toState.data && toState.data.access == "LOGGED_IN" && !user.loggedIn() ) {
event.preventDefault();
$state.transitionTo('account');
return false;
}
})
So far it works -- the user is redirected to the account
state if he's not logged in; but the resulting url in the browser is that which would have been if the user transitioned to one of the "forbidden" states. How can I prevent this from happening?
Metadata
Metadata
Assignees
Labels
No labels