angular - 角度返回 url 为空
问题描述
在我的应用程序中,如果人员未登录,则使用返回 url 登录
this.user=this._session.getEmployee();
if(!this.user){
this.router.navigate(['PA/Login'], {queryParams: {returnUrl:this.url}});
}
在登录组件中,ngOnInit
我正在尝试使用下面的代码。在我声明的构造函数中private route: ActivatedRoute
this.url=this.route.snapshot.paramMap.get('returnUrl');
这是我的路线配置
const routes: Routes = [
{path:"",redirectTo:"PA/Login",pathMatch:"full"},
{path:"PA",redirectTo:"PA/Login",pathMatch:"full"},
{path:"PA/Home",component:HomeComponent},
{path:"PA/Email/:url",component:EmailComponent},
{path:"PA/Login",component:LoginComponent},
{path:"PA/Login?returnUrl=:returnUrl",component:LoginComponent},
];
但它返回null。我在哪里犯错?
谢谢你的帮助
解决方案
您正在尝试从 获取查询参数paramMap
,当您应该通过时queryParamMap
:
this.route.snapshot.queryParamMap.get('returnUrl');
此外,您不需要路由器配置中的以下行:
{path:"PA/Login?returnUrl=:returnUrl",component:LoginComponent},
推荐阅读
- python - cv2.VideoCapture 参数不作为输入
- string - 如何在飞镖颤动的文本中将我的字符串的第一个字母大写?
- ios - 有没有办法在 Cocoa Pods 的单个目标中使用静态和动态框架
- css - 如何将 innerClass 样式应用于 appBase 中的 searchBox?
- visual-studio-code - 每次单元运行都会重复 VS Code Jupyter 日志记录输出
- mysql - 错误 AS-->您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 ', 附近使用的正确语法
- python - 如何使用 uptplot python 在 pandas 数据框中查找交集
- postgresql - PostgreSQL plpgsql。如何扩展二维数组的第二维?
- osgearth - 如何使用OpenSenceGraph生成正射影像、
- sql - 在编写 Vertica 查询时需要帮助