简体   繁体   English

使用Angular成功登录后使用$ location重定向

[英]Redirecting using $location upon successful login with Angular

I have an Angular service that handles logging in to my SPA. 我有一个处理登录到SPA的Angular服务。

 myApp.service('loginService', ['$rootScope', '$http', '$resource', '$cookies', '$location', function($rootScope, $http, $resource, $cookies, $location) { this.validateEmail = function() { $http({ url: myAppConfig.rootAPIUrl + 'Authenticate', params: { "playerId": $rootScope.data.emailId, "emailAddress": $rootScope.data.emailAddress }, method: "POST" }) .then(function(response) { if (response.data.Message == 'Success') { console.log('Login is successful.'); $cookies.put('emailId', $rootScope.data.emailId); $location.path("#/game").replace(); } $rootScope.msg = response.data; console.log(response.data); }, function(response) { console.log('Error in $http in controller...'); }); } }]); 

Upon successful login, my conditions check out in the if block, I get the console msg, I get my cookie set, but the setting of the location path to '#/game' doesn't work. 成功登录后,我的条件在if块中签出,我得到了控制台味精,得到了cookie集,但是位置路径设置为“#/ game”不起作用。 Any ideas on why? 有什么想法吗?

You just need to pass '/game' in the $location.path . 您只需要在$location.path传递'/game' That's how it works for me. 这就是我的工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 登录成功后在Firebase / Angularfire中使用成功的$ authWithOAuthRedirect进行重定向 - Redirecting after login with successful $authWithOAuthRedirect in Firebase / Angularfire 根据Angular中的登录条件进行重定向 - Redirecting based on login conditions in Angular AngularJS:重定向到登录页面但是还记得初始位置吗? - AngularJS: Redirecting to a login page but remember the initial location? 使用location.path()重定向 - Redirecting using location.path() 成功登录后要返回角度页面吗? - Going back to angular page after successful login? $ location.path没有重定向到Angular JS中的页面 - $location.path is not redirecting to page in Angular JS Angular ui路由器未使用$ location.path()重定向 - Angular ui router not redirecting with $location.path() 角$ location.path()不在所有页面上重定向 - Angular $location.path() not redirecting on all pages 成功登录Angular-node API后,即使使用CORS也会返回401(未经授权) - 401 (Unauthorized) after successful login Angular-node API even using CORS 如果直接调用,使用$ window.location.href在Angular中重定向有效,但如果从其他函数调用则无效 - Redirecting in Angular using $window.location.href works if invoked directly, but not if called from another function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM