Created
March 13, 2015 17:50
-
-
Save edin-m/f67ebb82b4c025a92d21 to your computer and use it in GitHub Desktop.
Redirection with angular ui router states.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is needed when there are multiple hierarchy states | |
// articles | |
// articles.view | |
// articles.add | |
// articles.config | |
// articles.config.type1 | |
// articles.config.type2 | |
angular.module('articles') | |
.run([ | |
'$rootScope', | |
'$state', | |
function($rootScope, $state) { | |
var redirect = { | |
'articles': '.view', | |
'articles.config': 'articles.view' | |
}; | |
$rootScope.$on('$stateChangeSuccess', function(event, toState) { | |
if(redirect[toState.name]) { | |
$state.go(redirect[toState.name]); | |
} | |
}); | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment