angular - 如果用户使用navigateByUrl更改密码不起作用,Angular 6重定向到应用程序的启动组件
问题描述
我目前在我的 Angular 6 应用程序的以下网址:
http://localhost:4200/dashboard/admin/users
如果管理员更改了他的凭据,我需要再次将他重定向到登录组件。
this.auth.updateCredentials(credentials).subscribe(
(data) => {
if (data == "success") {
this.showError = false;
if (credentials['user_id'] == this.loggedUser) {
//Redirect
localStorage.setItem('jwt', '')
localStorage.setItem('user_id', '')
localStorage.setItem('user_role', '')
this.router.navigateByUrl('login');
} else {
this.dialogRef.close();
}
}
if (data == "error") {
this.showError = true;
}
},
(error) => {
this.showError = true;
console.log(error);
}
);
我试过了this.router.navigateByUrl('login');
,this.router.navigateByUrl('/login');
但没有错误,也没有重定向
解决方案
尝试这个:
constructor(..., private router: Router, ...) {}
...
this.router.navigate(['/login']);
...
推荐阅读
- node.js - this._verify 不是登录功能
- reactjs - Redux-form 如何更新 Material-UI v4 textField 值?
- google-cloud-firestore - Javascript Firestore 客户端是否缓存文档引用?
- c# - 带有 .NET Framework 的 AWS Lambda 函数
- r - 在 dplyr 中,如何根据某一列是否在数据框中选择和过滤不同的列?
- scala - vert.x scala 可以热重载吗?
- java - JavaFX 为 GridPane 中的项目设置边距
- python - 通过 Django 中的 api 在多对多字段中添加新项目
- google-sheets - 在 Google 电子表格中使用趋势线预测 LTV
- python - 如何使用现有的元组列表创建新的元组列表