首页 > 解决方案 > Angular 函数中的路由

问题描述

我在这里有一个登录功能,允许用户登录并根据一条firebase信息(活动标志)是真还是假导航到某个组件(changepw)。即使我很好地阅读了数据,但当它为假时,我没有使用此代码获得重定向。已尝试更改密码和 /changepw。帮助!

  login(email: string, password: string): void {
    
      this.firebaseAuth.signInWithEmailAndPassword(email, password)


      .then(value => {

        var userId = value.user.uid;
        this.db.database.ref(('users/' + userId)).get().then(value => {
          var userInfo = value.toJSON();
          console.log(userInfo['active'])

          if ( userInfo == false ) {
            this.router.navigate(['changepw']);
          } else {
            this.router.navigate(['']);
          }

        })
      })
      .catch(err => {
        console.log('Something went wrong:', err.message);
        alert(err.message);
      });
    }

标签: javascriptangularfirebase

解决方案


如果你在 app-routing.module.ts 中有类似的东西

const routes : Routes = [
{path:"changepw",component abcComponent}
]

那么你应该在导航中添加前斜杠

this.router.navigate(['/changepw']);

如果您在控制台中有任何错误,appRouting 模块中的共享路由也会共享


推荐阅读