当route.params id更改时,routerLinkActive不会更新超链接

问题描述 投票:0回答:2

那是我的傻瓜:

https://plnkr.co/edit/C9W0pHvy27J83m25YUOJ?p=preview

这些是回溯问题的步骤:

  1. 打开项目'无休止'
  2. 该网址显示/projects/1/tests然后
  3. “测试链接”以橙色突出显示
  4. 将网址栏中的路线更改为/projects/2/tests
  5. 以前突出显示的“测试链接”现在不再是橙色了。

为什么活动类被有角度删除?

angular angular2-routing
2个回答
1
投票

目前这不起作用,请参阅#13865


0
投票
***app.module.ts***    


  { path: 'projects', component: ProjectListComponent , children: [
    { path: '', redirectTo: 'tests', pathMatch: 'full' }, /* projects/id causes can not match any route */
    { path: ':id/tests', component: TestsListComponent },
    ]
  },

  { path: '', redirectTo: 'projects', pathMatch: 'full' },
   { path: '**', component: NoRouteFoundComponent } /

];

项目-list.component.html

 <nav style="background:gray;">
      <select (ngModelChange)="onChangeProject($event)" [(ngModel)]="currentProject">
                <option *ngFor="let p of projects" [ngValue]="p">
                    {{p.name}}
                </option>
            </select> 
            <button [disabled]="!currentProject"  (click)="open()">Open project</button>


            <a *ngIf="isMenuVisible" [routerLink]="['/projects', currentProject.id, 'tests']"
    [routerLinkActiveOptions]="{ exact: true, __change_detection_hack__: currentProject.id }" >Tests link
            </a>


        <span>Logged out</span>

你应该添加:[routerLinkActiveOptions] =“{exact:true,change_detection_hack:currentProject.id}”

© www.soinside.com 2019 - 2024. All rights reserved.