routerLinkActive 不触发好link

routerLinkActive don't trigger the good link

所以我已经阅读了一些关于这个主题的文章,但没有找到答案。

用例

问题

active class 未添加到好商品中

app.routing.ts

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    children: [
      { path: '', redirectTo: 'tools', pathMatch: 'full' },
      { path: 'tools', component: ToolsComponent },
      {
        path: 'audio',
        loadChildren: () => import('./audio/audio.module').then(m => m.AudioModule)
      },
    ]
  }
];

audio.module :

@NgModule({
  declarations: [AudioComponent, AudioDetailsComponent],
  imports: [SharedModule, AudioRoutingModule],
})

audio.routing.ts :

const routes: Routes = [
  { path: '', component: AudioComponent },
  { path: ':id', component: AudioDetailsComponent }
];

menu.component.html(在 HomeComponent 中):

<mat-nav-list fxLayout="column">
  <a mat-list-item [routerLink]="['/tools']" routerLinkActive="active">
    <span mat-line>Tools</span>
    <mat-icon matListIcon>build</mat-icon>
  </a>
  <a mat-list-item [routerLink]="['/audio']" routerLinkActive="active">
    <span mat-line>Audio</span>
    <mat-icon matListIcon>headset</mat-icon>
  </a>
</mat-nav-list>

我发现它不起作用的“原因”: 在 audio.component.ts 中,我快速连续调用 router.navigateThis answer solved my issue

我只需要重新格式化我的代码。