angular - Angular Router:导航到上一个路由转义字符
问题描述
我目前正在通过创建路由历史来创建一个简单的后退按钮。每次用户导航到新路线时,我都会在完成导航之前将当前 url 存储在一个数组中,例如:
public routeHistory: string[] = [];
...
if (event instanceof NavigationEnd) {
this.routeHistory.push(event.url);
}
...
然后我创建了一个导航到上一条路线的方法:
public navigateBack(): void {
// If there is a previous route
if (this.routeHistory.length > 1) {
const previousRoute: string = this.routeHistory[this.routeHistory.length - 2];
this.router.navigate([previousRoute]).then(result => {
// If navigation was successful
if (result) {
this.routeHistory.pop();
}
});
}
}
一切正常,直到 previousRoute 包含参数,例如/route;param=value
因为该router.navigate
方法转义 '/' 和 '=' 导致路由器导航到/route%3Bparam%3Dvalue
.
有没有办法防止这种情况?
解决方案
它应该与router.navigateByUrl(url)
.
推荐阅读
- bash - 如何仅获取要在预提交挂钩中处理的文件的更改部分?
- c - Cmocka:在测试失败时打印上下文
- uwp - MenuFlyout 失败
- java - SQL查询从postgresql数据库表中具有数组数据类型的列中获取数据
- postgresql - SQL获取所有相关记录
- html5-video - Google Meet 使用哪些技术进行屏幕和音频/视频录制?
- django - 我真的需要在 Django 模板中使用 {% load static %} 吗?
- python - 如何使用 python 打印这个菱形图案?
- c# - 如何通过检查列名是否与按钮名称对应来使用循环更新我的数据库?
- carousel - Boostrap 4 轮播指示器形状