javascript - 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);
});
}
解决方案
如果你在 app-routing.module.ts 中有类似的东西
const routes : Routes = [
{path:"changepw",component abcComponent}
]
那么你应该在导航中添加前斜杠
this.router.navigate(['/changepw']);
如果您在控制台中有任何错误,appRouting 模块中的共享路由也会共享
推荐阅读
- selenium-webdriver - Selenium Webdriver 节点 js
- migration - 哪里可以找到 Kate 文本编辑器键映射/快捷方式配置文件?
- laravel - 如何制作对象而不是数组的 Laravel 集合
- google-cloud-datastore - 每个请求的云 ndb 命名空间
- python - 根据另一个列表对列表进行排序,长度不均匀
- node.js - 使用 Nodejs 在 PostgreSQL 中进行定时插入操作
- c# - 在 Windows 上运行 janusGraph
- javascript - 如何正确使用模板将项目绑定到 JS 中的 sap.m.table
- android - 任务“:app:mergeLibDexDebug”执行失败
- r - 如何从 ggplot 对象中删除比例?