如何解决使用 Facebook 登录后无法重定向到主页
我试图在 Facebook 登录后重定向到我的主页,它成功返回了存储在 localStorage 中的令牌,但之后,它停留在登录页面上并且不重定向。
loginWithFB() {
this.facebook.login(['public_profile','user_friends','email']).then((res: FacebookLoginResponse) => {
this.facebook.api('me?fields=id,name,email,first_name,last_name',[]).then(profile => {
let data = {email: profile['email'],first_name: profile['first_name'],last_name: profile['last_name'],input_token: res.authResponse.accessToken,phone: '1234567890'};
this.api.loginWithFacebook(data).then((res) => {
this.checkLoginResFB(res);
},(err) => {
console.log("Error in API");
console.log(err);
});
});
})
.catch(e => console.log('Error logging into Facebook',e));
}
checkLoginResFB(res) {
if (res.success == false) {
console.log("unable to login");
console.log(res.message);
} else {
console.log("login successfull");
localStorage.setItem('token',JSON.stringify(res.token));
this.router.navigateByUrl('/home'); //Redirect to Home Page
}
}
解决方法
路由器由于某种原因无法工作,我不知道,但 vanilla javascript 可以
window.location.replace('/home');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。