I'm encountering a common issue that I haven't been able to resolve despite trying different approaches. My goal is to implement dynamic animations in my application states, where the login process involves some animations before transitioning into the main interface. Here's how I've structured the views:
$stateProvider
.state('login', {
url: '/login',
title: "Login",
views: {
"master": {
controller: "LoginController",
templateUrl: "/components/login/login.html",
authentication: false
}
}
})
.state("logout", {
url: "/logout",
title: "Logout",
authentication: false
})
.state('foo', {
url: '/',
controller: "HomeController",
views: {
"master": {
templateUrl: '/views/masterView.html'
},
"sidebar@foo": {
templateUrl: '/views/sidebar.html'
},
"header@foo": {
templateUrl: '/views/header.html'
}
}
})
.state('foo.inventory', {
url: '/inventory',
title: "Inventory",
views: {
"content@foo": {
controller: "InventoryController",
templateUrl: "/components/inventory/inventory.html"
}
}
});
However, when I try redirecting to the logout state, it seems to get stuck and doesn't progress further. Here's how I'm handling this scenario:
function run($http, $rootScope, $cookieStore, $state, $templateCache, $timeout, AuthService) {
var timeout;
FastClick.attach(document.body);
$rootScope.globals = $cookieStore.get('globals') || {};
if ($state.current.name !== 'login' && !$rootScope.globals.guid) {
$state.go('login');
} else if ($state.current.name === 'login' && $rootScope.globals.guid) {
$state.go('foo');
}
$rootScope.$on('$stateChangeStart', function(event, next, current) {
var needAuth = next.authentication !== undefined ? next.authentication : true;
if (needAuth) {
if (!AuthService.isAuthorized()) {
event.preventDefault();
if (AuthService.isAuthenticated()) {
$state.go('foo');
}
}
}
if (next.name === 'logout') AuthService.logout($rootScope.globals);
});
}
Despite implementing what seems to be correct logic, why does $state.go('login')
yield an unexpected outcome? If anyone can provide insight or pinpoint the issue, I'd greatly appreciate it.