2017-06-22 252 views
0

我想重定向到登录屏幕,当我的存储其他主屏幕没有UABGlobalAdminId,为此,我用$ urlRouterProvider.otherwise,但它不能正常工作。当我尝试调试控制台没有达到它。任何人都可以请建议help.Thanks。

我有这个在我的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'); 
    } 
    }); 
+0

看到这个SO问题[否则在StateProvider](https://stackoverflow.com/questions/16793724/otherwise-on-stateprovider) –

回答