【问题标题】:Angular route: redirectTo when using multiple param角度路线:使用多个参数时的redirectTo
【发布时间】:2021-03-31 15:30:17
【问题描述】:

我有这样的路线

const pipelinesRoutes: Routes = [
  {
    path: ':type',
    component: CatalogComponent,
    canActivate: [LoggedInGuard],
    children: [
      {
        path: '',
        component: CatalogContentComponent,
      },
      {
        path: ':domain/:categoryId',
        component: CatalogContentComponent,
      },
    ],
  },
  { path: '', redirectTo: 'skills', canActivate: [LoggedInGuard] },
];

如果没有提供类型,我想将我的应用程序重定向到技能(:类型),它在开始时工作正常,但一旦我刷新说有这个 url。

catalog/skills/technical

它重定向到

catalog/skills/skills/technical

【问题讨论】:

  • 只是猜测,但 pathMatch prefix 会在重定向中起作用吗?
  • 不工作尝试 pathMatch 前缀/完整
  • 请解释:domain:categoryId的目的是什么
  • catalog/skills/technical 中,如果skills:type,那么technical 没有路径匹配,因为它只接受:domain/:categoyId
  • @T.SunilRao 是的。

标签: angular angular-router


【解决方案1】:

感谢 T. Sunil Rao 帮助我。 是的,我的路线有问题。 我在路由的帮助下传递了空参数

this.router.navigate([domain, ''], { relativeTo: this.route });

但是在刷新时它不会将该空参数视为参数,因此会重定向。

catalog/skills/technical 没有填满任何路线,所以它重定向到技能/ 正确的路线应该是

const pipelinesRoutes: Routes = [
  { path: '', redirectTo: 'skills', pathMatch: 'full' },
  {
    path: ':type',
    component: CatalogComponent,
    canActivate: [LoggedInGuard],
    children: [
      {
        path: '',
        component: NoDomainContentComponent,
      },
      {
        path: ':domain',
        component: CatalogContentComponent,
        children: [
          {
            path: ':categoryId',
            component: CatalogContentComponent,
          },
        ]
      },
    ],
  },
];

使用另一个子组件,因为我不想刷新组件,想使用相同的组件并过滤数据。

【讨论】:

    猜你喜欢
    • 2015-08-17
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    相关资源
    最近更新 更多