Angular 路由器:导航到上一个路由转义字符
Angular Router: Navigating to previous route escapes characters
我目前正在通过创建路由历史记录来创建一个简单的后退按钮。每次用户导航到新路线时,我都会在完成导航之前将当前 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)
。
我目前正在通过创建路由历史记录来创建一个简单的后退按钮。每次用户导航到新路线时,我都会在完成导航之前将当前 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)
。