URL 在 angular 中重写缺少参数?

URL rewriting in angular with missing param?

我有 URL 在 Angular4 中重写的场景,需要一个解决方案。为此,我需要拦截第一个 URL 并进行要求更改,然后重定向到新路径。

有没有可能在路由匹配机制之前拦截那个请求

我的场景

最初我有,

{ path: 'page/:id', component: SomeComponent },

> http://localhost/page/<id>

我现在必须将其更改为

{ path: 'page/:type/:id', component: SomeComponent },

现在,之前的 URL 已重定向到新的 url(路径)

> http://localhost/page/<id> >> http://localhost/page/<type>/<id>

问题是我没有 值,最好的方法是什么?

一个是,我将把之前的 URL 借给 componentX(没有模板),当该组件运行时我获取一些 然后从该 componentX 重定向到新路径?

将解析器添加到您的路由可以解决您的问题

https://alligator.io/angular/route-resolvers/

https://angular.io/api/router/Resolve