Does anybody know how to change the ui-router state without changing the url? As the code below shows; in some cases the user needs to be redirected to 403 or 401 states. I would like to be able to do this redirect without changing the url.
Regards, klmdb
// make sure authGetCurrent has ran before routing starts $rootScope.$on("$locationChangeSuccess", function(event, next) { event.preventDefault(); AuthService.loadCurrentAuth().then(function(){ $urlRouter.sync(); }, function(){ console.log("BIG ERROR!!!"); }); }); // Configures $urlRouter's listener *after* your custom listener $urlRouter.listen(); $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) { var requiredLogin = (toState && toState.data ? toState.data.requiredLogin : false ), requiredGroupRights = (toState && toState.data ? toState.data.requiredGroupRights : false ); // require the user to have at least one of these rights in the current group if (requiredLogin && !AuthService.isLoggedIn()) { event.preventDefault(); $state.transitionTo('401'); return; } if(requiredGroupRights){ var i, hasRight = false; for(i=0;i<requiredGroupRights.length;i++){ if(GroupService.checkGroupRights(toParams.groupId, requiredGroupRights[i])){ hasRight = true; break; } } if(!hasRight){ event.preventDefault(); $state.transitionTo('403'); return; } } });