Angular 路由重定向而不切断 url

Angular routing redirect without cutting the url

目前我正在尝试创建一个 Angular 应用程序,用户可以在其中接收特定的 URL :例如 /answer/1234d1fjs8 并且每当 "answer" 在 URL路由应该打开组件"answer".
我已经通过路由和重定向完成了此操作,但遗憾的是应用程序删除了 id (1234d1fjs8) 并且路由后的 url 只是 /answer.
我要么需要在 variable/service 中保护 /answer 之后的 url 部分,要么在不剪切 url 的情况下重定向。我更喜欢不剪切的重定向。

来自应用程序的路线-routing.module.ts :
{ path: 'answer', component: SummaryComponent}, { path: 'answer',redirectTo:'/answer',pathMatch: 'prefix'}

试试这个

{ path: 'answer/:id', component: SummaryComponent}

在你的路由中你没有提到参数。所以你的参数没有得到

更改路由

{ 路径:'answer/:id',组件:SummaryComponent}