1:簡單的登陸檢查html
$stateProvider .state('index', { url: "/", templateUrl: 'views/forwards/intro.html', controller: 'ForwardsIntroCtrl', data: { loginCheck: false } }) .state('account', { url: "/account", templateUrl: 'views/forwards/account.html', controller: 'ForwardsAccountCtrl', data: { loginCheck: true } })
配置參數:loginCheck(這裏能夠自定義)ide
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { console.error(toState, toState.data.loginCheck); if (!$rootScope.logined && toState.data.loginCheck) { console.error('not login!'); $location.path('/') } });
根據某個rootScope值和loginCheck判斷是否登陸ui
2:角色檢查url
能夠參考:http://stackoverflow.com/questions/22537311/angular-ui-router-login-authenticationspa
原理大概是同樣的。code