Reputation: 511
If I put notify to true, does not render the login.html, is a blank page. If I put as false, but returns renders me several errors in the console:
RangeError: Maximum call stack size exceeded
at $.resolve (angular-ui-router.min.js:1)
at b (angular-ui-router.min.js:1)
at Object.x.transitionTo (angular-ui-router.min.js:1)
at Object.x.go (angular-ui-router.min.js:1)
at app.js:317
at p.$broadcast (angular.min.js:3)
at Object.x.transitionTo (angular-ui-router.min.js:1)
at Object.x.go (angular-ui-router.min.js:1)
at app.js:317
at p.$broadcast (angular.min.js:3)
My code router:
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams) {
var shouldLogin = !$window.sessionStorage.token && !AuthenticationService.isLogged;
$rootScope.Authenticated = shouldLogin;
//redirect only if both isAuthenticated is false and no token is set
// if (!AuthenticationService.isLogged && !$window.sessionStorage.token) {
// $state.go('login');
// }
//console.log($rootScope.Authenticated);
if(shouldLogin) {
$state.go('login', {}, {notify: false, location: false});
event.preventDefault();
return;
}
});
Upvotes: 1
Views: 50
Reputation: 123861
I would say, that you can go your way, just ... add a line to NOT redirect, when already going to login:
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams) {
var alreadyGoingToLogin = toState.name === "login";
if(alreadyGoingToLogin) {
return
}
...
Check these with working examples:
Upvotes: 1