0

I want to redirect to the login screen when no UABGlobalAdminId in my storage else home screen and for that, I used $urlRouterProvider.otherwise but it's not working fine.When I try debugging the console is not reaching it.Can anyone please suggest help.Thanks.

I have this in my app.js,

  $stateProvider
    // Home
    .state('home', {
        url: '/',
        templateUrl: 'app/templates/home.html',
        controller: 'homeCtrl'
    })
    .state('login', {
        url: '/login',
        templateUrl: 'app/templates/login.html',
        controller: 'loginRegCtrl'
    })
     $urlRouterProvider.otherwise(function($injector, $location){
    var state = $injector.get('$state');
    if(localStorage.getItem('UABGlobalAdminId')){
      state.go('home');
    } else {
      state.go('login');
    }
  }); 
FlashCode
  • 85
  • 1
  • 11
looker
  • 1

1 Answers1

0

You need to check "logged in" status on every route change. for more detailed ans follow this link https://stackoverflow.com/a/44676307/3828728