angularjs - Route change after login not working with Angular js, ui-router, satellizer and IE 11 -
in chrome, firefox, , opera when user logs in app redirects 'dash' state. in ie 11 logs in, redirects 'dash' state 'login' state.
parts of index:
<meta http-equiv="x-ua-compatible" content="ie=11" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-rc1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.js"></script> <script src="js/angular-ui-router.min.js"></script>
....
<div ui-view></div>
part of app.js:
var app = angular.module('myapp', ['ui.router', 'monospaced.elastic', 'satellizer', 'slick', 'chart.js', 'wu.masonry', 'ngsanitize']); app.config(function($stateprovider, $urlrouterprovider, $authprovider) { $stateprovider .state('login', { url: '/login', templateurl: '../login.html', controller: 'logincontroller' }) .state('dash', { url: '/dashboard', templateurl: '../dashboard.html', controller: 'dashboardcontroller' }) .state('home', { url: '/', templateurl: '../home.html' }); $urlrouterprovider.otherwise('/'); });
this login.js:
app.controller('logincontroller', function($scope, $state, $auth, $http, $rootscope) { $scope.login = function(user) { $scope.showerror = false; $scope.showvalidationerror = false; $scope.showrateerror = false; $scope.shownousererror = false; if(angular.isundefined(user)) { $scope.showvalidationerror = true; } console.log("do login"); $auth.login({ email: user.email, password: user.password }).then(function(response) { $auth.settoken(response); console.log("login success"); $state.go('dash'); }).catch(function(error) { console.log("login error " + error.data.message + " " + error.status); if(error.status === 401) { $scope.showerror = true; } if(error.status === 403) { $scope.showrateerror = true; } if(error.status === 422) { $scope.showvalidationerror = false; } if(error.status === 500) { $scope.shownousererror = true; } }); }; });
part of dash.js:
$http({ method: 'get', url: '/api/project/', headers: { 'authorization' : 'bearer ' + window.localstorage.satellizer_token } }).then(function(response){ $scope.projects = response.data; $scope.$broadcast('controllerupdate', $scope.projects); }, function errorcallback(response) { if(response.status === 401) { $state.go('login'); } });
seems logs in successfully, goes 'dash' when tries 'get' request dash fails due authorization...
update
now it's getting dash sometimes, project data doesn't load. not sure problem :/ timing issue? , why doesn't happen in other browsers?
any appreciated.
so turns out ie doesn't trailing slashes...
doing on url: '/api/project/', returning 401 error ie , redirecting 'login'.
Comments
Post a Comment