对于访问我们网站的SEO和遗留外部链接,我们需要为弃用的网址提供后备路由 . 命名出口的事情变得棘手 . 现在尝试找到正确的设置,以指定重定向到更新的命名插座的路由 .

例如:
https://url.com/prod/000(myOutlet:foo)应重定向到https://url.com/prod/000(newOutlet:some/foo),而000当然是动态的

现在一些反映新旧路线的代码:

OLD:
https://url.com/prod/000(myOutlet:foo)
https://url.com/prod/000(myOutlet:bar)
{
  path: ':vars',
  outlet: 'myOutlet',
  component: VarsComponent
}

NEW:
https://url.com/prod/000(newOutlet:some/error)
https://url.com/prod/000(newOutlet:some/empty)
https://url.com/prod/000(newOutlet:some/foo)
https://url.com/prod/000(newOutlet:some/bar)
{
    path: 'some',
    outlet: 'newOutlet',
    component: VarContainerComponent,
    children: [
      {
        path: 'empty',
        component: VarEmptyComponent
      },
      {
        path: 'error',
        component: VarErrorComponent
      },
      {
        path: ':var', // OLD implementation should point here
        component: VarContentComponent
      }
    ]
  }

如何指定OLD实现重定向到新路径:':var'route?

// fake assumption, redirectTo code not working
// 1. simpler solution, using just a static route (currently all external links use this one)
{
   path: 'foo',
   outlet: 'myOutlet',
   redirectTo: '**(newOutlet:some/foo)',
},
// 2. more advanced solution, variables being redirected
{
   path: ':var',
   outlet: 'myOutlet',
   redirectTo: '**(newOutlet:some/:var)',
},

当然,要提到myOutlet在新部署的应用程序中不再存在,我们仍需要能够对其做出反应 .

我创建了一个可以用作游乐场的stackblitz,它包含一个具有动态id并且在本主题中提到的名为router-outlet的路由 . https://stackblitz.com/edit/angular-router-outlet-redirectto