Unfortunately, you cannot use ui-srefto refer to an abstract state.
you can try something like:
$rootScope.$on('$stateChangeStart', function(event, toState, toParams){
if(toState.name == 'library'){
event.preventDefault();
$state.go('library.albums', toParams);
}
}
Instead of hard-coding each state redirection, you can do something like:
$stateProvider
.state('library', {
url: '/library',
data: {
redirect: 'library.albums'
}
})
.state('library.albums', {
url: '/albums',
data: {
redirect: false
}
});
$rootScope.$on('$stateChangeStart', function(event, toState, toParams){
if(toState.data && toState.data.redirect){
event.preventDefault();
$state.go(toState.data.redirect, toParams);
}
}
source
share