简体   繁体   English

当用户使用ionic登录时,停止用户进入登录页面

[英]stop user to go login page when user logged in using ionic

I want that if a user is logged in he can't go to the login and OTP page by hardware back button. 我希望用户登录后无法通过硬件后退按钮进入登录和OTP页面。

.controller('viewoemCtrl', function($rootScope,$scope,$http,$ionicPopup,$state,$ionicHistory,$ionicLoading,productService,$ionicPlatform) {
$scope.user = {};  //declares the object user

 $ionicPlatform.onHardwareBackButton(function () {
    if (true) { // your check here
        $ionicPopup.confirm({
            title: 'Exit from App!',
            template: 'are you sure you want to exit?'
        }).then(function (res) {
            if (res) {
                navigator.app.exitApp();
            }
        })
    }
 })
 })

You don't need to check the click on the back button, because that itself will call a state transition from ui-router. 您无需检查单击后退按钮,因为它本身将调用ui-router的状态转换。 just register a callback to the $stateChangeStart event fired by ui-router and control there if the user is logged in and if the target state is login, in this case you prevent the transition. 只需注册一个由ui-router触发的$stateChangeStart事件的回调,并在其中控制用户是否登录以及目标状态是否为登录,在这种情况下,可以防止过渡。 This will handle any case of state transition (the back button, a direct link from the menu etc.) 这将处理任何状态转换的情况(后退按钮,菜单中的直接链接等)

 $rootScope.$on('$stateChangeStart', function(event, toState, toParams,
  fromState, fromParams){ 
   //userIsLogged is a flag you should retrieve from your code
   if(userIsLogged && toState === 'login'){ 
     event.preventDefault(); 
   }
 })

take a look at the documentation 看一下文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ionic 1 - 如果用户未登录则显示登录页面,如果用户已登录则跳过 - Ionic 1 - Show login page if user not logged and skip if user is already logged 如果用户已登录离子,如何跳过登录页面 - how to skip login page if user already logged in in ionic 如果用户已登录离子框架,如何跳过登录页面 - How to skip login page if user is already logged in ionic framework 当用户未登录或用户尝试使用angularjs直接从URL访问页面时,重定向到登录 - Redirect to login when user is not logged in or user tries to access page directly from URL using angularjs 使用Ionic中的$ state.go将用户路由到另一个HTML页面 - Route user to another HTML page using $state.go in Ionic angularjs + ui-router:当用户未登录每个状态更改时,重定向到登录页面 - angularjs + ui-router: redirect to login page when user is not logged in on each state change 如果已经登录 ionic,则重定向用户 - redirect user if the already logged in ionic 如果用户使用Ionic登录,则重定向到仪表板 - Redirect to dashboard if user is logged in with Ionic 如果用户尚未登录Angular JS,则重定向到登录页面 - Redirect to a login page if the user is not yet logged in Angular JS Angular-当用户未登录时,$ state.go不能按预期重定向 - Angular - $state.go not redirecting as expected when user is not logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM