Angular 如何在角度路由中通过重定向到获取url片段(锚参数)

Angular 如何在角度路由中通过重定向到获取url片段(锚参数),angular,url-routing,Angular,Url Routing,我试图通过路由器表进行角度路由重定向,想知道有没有简单的方法可以通过重定向获得url片段。我有这样的想法: { path: ':word', redirectTo: 'blah/:word', pathMatch: 'full' } { path: ':word', resolve: { _: RedirectResolver }, component: DummyComponent, // We never go here } 当我使用localhost

我试图通过路由器表进行角度路由重定向,想知道有没有简单的方法可以通过重定向获得url片段。我有这样的想法:

{
   path: ':word',
   redirectTo: 'blah/:word',
   pathMatch: 'full'
}
{
   path: ':word',
   resolve: { _: RedirectResolver },
   component: DummyComponent, // We never go here
}
当我使用localhost:4200/test这样的参数运行它时,fragment会将其重定向到localhost:4200/blah/test,而不使用片段。我已经通过使用片段重定向到正确位置的解析程序绕过了这个问题,但这感觉很愚蠢,因为我需要像这样将虚拟组件放到路由器上:

{
   path: ':word',
   redirectTo: 'blah/:word',
   pathMatch: 'full'
}
{
   path: ':word',
   resolve: { _: RedirectResolver },
   component: DummyComponent, // We never go here
}

如果我省略了这个组件,那么Angular就不起作用了。有什么好的或本地的方法来完成这种行为吗?

你可以将“preserveFragment”设置为true(doc:)

我不想用路由器来完成。导航,但通过路由器表重定向Tooh是的,对不起,我读得太快了,现在在我的计算机上读不到,路径和重定向值接受“#fragment”吗?示例“:word#fragment”->“blah/:word#fragment”我到电脑前会试试这个