gpt4 book ai didi

Angular 4 和 angularfire2 路由器导航,但前一个组件仍在显示

转载 作者:太空狗 更新时间:2023-10-29 18:30:35 24 4
gpt4 key购买 nike

我正在使用 Angular 4 和 angularfire2 (firebase) 开发一个项目,我试图在用户使用第三方(Google 或 Facebook)成功登录后导航到主页。

问题是在使用 angularfire2 弹出窗口对用户进行身份验证后,路由器正确导航(浏览器中的链接发生变化并且主页组件可见)但登录组件仍然存在!

我不确定问题是与弹出窗口中的 angularfire2 登录有关还是与 angular 4 本身有关,有什么建议吗?

angularfire2 回调:

signInWithGoogle() {
this.angularFireAuth.auth.signInWithPopup(new
firebase.auth.GoogleAuthProvider()).then((infos) => {
this.router.navigate['/home'];
});
}

路由器配置:

const memberSpaceRoutes: Routes = [
{ path: 'sign-in', component: SignInComponent },
{ path: 'home', component: Home},
]

最佳答案

我不确定这个解释,但你不在 Angular 知道的上下文(特别是区域)

导入 NgZone 并在 then

中使用
this.zone.run(() => {this.router.navigate['/home']})

关于Angular 4 和 angularfire2 路由器导航,但前一个组件仍在显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46393857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com