我有一些在我的应用程序中需要支持的旧URL,其中包括一个#,例如http://localhost:4200/#/result/1234。
我已设置下列重定向路线:
{ path: 'result/:id', pathMatch: 'full', redirectTo: 'new-result/:id' }
当URL不包含#:,例如http://localhost:4200/result/1234时,它工作得很好。
但是当URL包含一个#时,路由就不匹配了,它只是重定向到默认路由,例如http://localhost:4200/#/result/1234。
对于如何自动设置我的角度应用程序,以便在进行路由匹配之前将http://localhost:4200/#/result/1234转换为http://localhost:4200/result/1234,有什么想法吗?
我用的是角版13。
谢谢!
发布于 2022-05-03 11:58:51
通过订阅app组件(app-component.ts)构造函数中的路由事件,我就能够做到这一点:
this.router.events.subscribe((event: Event) => {
if (event instanceof NavigationStart) {
let url = event.url;
if (url.includes('/#/result')) {
let urlSplit = url.split('/');
this.router.navigate(['result', url.split('/')[3]]);
}
}
});https://stackoverflow.com/questions/72088496
复制相似问题