在我的Angel 15应用程序的一个页面中,我有一台路由可以显示嵌套的路由:

<app-sidebar></app-sidebar>
<ion-router-outlet></ion-router-outlet>

我的app-sidebar美元在哪里:

<ion-list>
  <ion-item *ngFor="let route of profileRoutes">
    <ion-button
      [routerLink]="route.path"
      routerLinkActive="active-item">
      {{ route.label }}
    </ion-button>
  </ion-item>
</ion-list>

profileRoutes实现此接口:

export interface ProfileRoute {
  path: string;
  label: string;
}

下面是我的路由的配置:

const routes = [
  {
     path: 'profile',
     loadComponent: () =>
       import('./path-to-component').then(
         m => m.Component
       ),
     children: childrenRoutes,
  }
]
const childrenRoutes = [
  {
    path: 'route-1',
    loadComponent: () =>
      import('path-to-component').then(
        m => m.Component
      ),
  },
  {
    path: 'route-2',
    loadComponent: () =>
      import('path-to-component').then(
        m => m.Component
      ),
  },
  ...
]

Behavior

  1. 点击按钮route-1一次,即可正常工作(重定向至/profile/route-1).
  2. 然后,点击按钮route-2,用户不会得到重定向,加上所有按钮获得类active-item,表示所有路由都被触发为active.
  3. 如果我右击并"在另一个选项卡中打开",路由就会按预期触发,并且我可以从操作1重新启动.

此外,此警告记录在操作2上.

在即将发布的ANGLE版本中,导航到/Profile/Route-1将改为导航到/Profile/Route-2.可能需要从UrlCreationOptions中删除relativeTo

但我从来没有在任何地方用过relativeTo.

我try 在辅助ion-router-outlet上添加一个名称,并在childrenRoutes中的路径上添加outlet属性,但没有成功.

推荐答案

This happens because routerLink automatically set the redirectTo option to your current route, and you want it to be your parent route.
You could use activatedRoute to find your parent route and redirectTo it. Note that now you have to add profile to your path.

<ion-button
    [routerLink]="['profile', route.path]"
    [redirectTo]="activatedRoute.parent"
    routerLinkActive="active-item">
    {{ route.label }}
</ion-button>

Angular相关问答推荐

垫-菜单未以17.2.3角显示

try 测试具有Angular material 下拉列表的组件时,在Angular 17中发现&q;错误的意外合成属性@TransitionMessages

在不使用散列(#)路由的情况下刷新Angular 8的SPA时,删除404错误

Angular 类型的表单不能分配给分部类型

如果过滤器在rxjs流中触发,则返回空数组

ANGLING HTTP.GET()返回包含数据的数组

当我更新S显示的数据时,为什么我的垫表用户界面没有更新?

RxJS轮询+使用退避策略重试

ngx-http-client 在 Angular 16 中已弃用

Angular 15 在 URL 中使用@进行路由

Storybook 和 Angular 交互游戏测试未定义预期

包含与 ngFor 相关内容的 HTML 输入

个人修改 Angular CLI - 创建新应用

RxJS - .withLatestFrom 的多个来源

如何从组件模板将数组作为 Input() 传递?

Angularmaterial步进器:禁用标题导航

在 Angular 4 中播放声音

Angular 4 设置下拉菜单中的选定选项

具有多个订阅者的 Angular 2 Observable

如何导航到同级路由?