在AngularJS中刷新后要保持在同一页面上吗?它正在重定向到登录页面

在AngularJS中刷新后要保持在同一页面上吗?它正在重定向到登录页面,angularjs,Angularjs,这是我的控制器代码。我正在使用会话存储和$rootScope,但$rootScope正在刷新后将所有值设置回false。当我只使用sessionStorage时,它会设置会话值,但不会从登录页面重定向到登录页面。有人能帮我吗 函数LoginCtrl($scope、$rootScope、$window、$location、$http、$state、loginService、$cookies、$sessionStorage){ $rootScope.loggedIn=false; $rootScop

这是我的控制器代码。我正在使用会话存储和$rootScope,但$rootScope正在刷新后将所有值设置回false。当我只使用sessionStorage时,它会设置会话值,但不会从登录页面重定向到登录页面。有人能帮我吗

函数LoginCtrl($scope、$rootScope、$window、$location、$http、$state、loginService、$cookies、$sessionStorage){
$rootScope.loggedIn=false;
$rootScope.registereduser=false;
$rootScope.registration=false;
$scope.changeState=函数(){
$rootScope.registration=true;
$state.go('register');
}
$scope.logout=函数(){
$window.localStorage.clear();
$rootScope.loggedIn=false;
$rootScope.registereduser=false;
$rootScope.registration=false;
}
$scope.gotoHome=函数(){
$window.localStorage.clear();
$rootScope.loggedIn=false;
$rootScope.registereduser=false;
$rootScope.registration=false;
}
$scope.showGroup=函数(用户名、密码){
$scope.userId=用户名;
$scope.password=密码;
如果((用户名==null | |用户名==“”)和&(密码==null | |密码==“”)){
警报(“请输入有效凭据”);
$rootScope.loggedIn=false;
}否则
$http.post(“./rest/jsonServices/authentication?userId=“+$scope.userId+”&password=“+$scope.password”)。成功(函数(数据){
var landingPage='';
$scope.inValidCredentials=false;
$rootScope.role=data.role;
if(data!=null&&data.accessible==true){
//sessionStorage.user=JSON.stringify(数据);
sessionStorage.loggedIn=true;
$rootScope.loggedIn=sessionStorage.loggedIn;
$rootScope.loggedInuserId=用户名;
$rootScope.menuType=data.defaultMenuType;
$scope.operational=data.operational;
$scope.lifeCycle=data.lifeCycle;
$scope.qbot=data.qbot;
$scope.admin=data.admin;
if($scope.admin){
$state.go('admin');
$scope.menubar=false;
}else if($scope.operation){
$state.go('dashboard');
$scope.var1=true;
}else if($scope.lifeCycle){
$state.go(‘生命周期’);
$scope.menubar=false;
}else if($scope.qbot){
$scope.menubar=false;
$state.go('qbot'))
}
}else if(data!=null&&data.accessible==false){
$rootScope.registereduser=true;
$rootScope.loggedIn=false;
}否则{
警报(“无效凭证”);
data.message=“无效的用户ID或密码”;
$scope.error=data.message;
}
}).错误(函数(数据){
警报(“请输入有效凭据”);
});
}
}

当重定向失败时,您的控制台中是否出现任何错误?未发现错误,但我可以看到正在存储会话值,但我无法使页面保持不变会话值存在,但重定向到登录页面Kxng Kombian您能建议一些解决方案吗?状态名称有效吗?是的,所有状态名称都有效,状态都有效按原样显示,但重定向到登录页面