function checkState(check, state){ var setTo = check; var states = state.get(); var foundAlternative = false; var currentState = state.current; if (!currentState.views){ return setTo; } var checkView = setTo+'_'+Object.keys(currentState.views)[0]; for (var i=0;i 1){ for (var key in data.views){ var copy = {}; angular.copy(data, copy); copy.views = {}; copy.views[key] = data.views[key]; copy.url = '/'+key+data.url; $stateProvider.__state(statename+'_'+key, copy); } return $stateProvider; } } } $stateProvider.__state(statename, data); return $stateProvider; } }]) .directive('uiSref', function($state){ return { restrict: 'A', priority: -1, link: function(scope, element, attrs){ attrs.uiSref = checkState(attrs.uiSref, $state); } } }) ;