【发布时间】:2020-04-07 07:51:49
【问题描述】:
在我的应用中有两个路由,home 和 page1
这是导航到相关路线的两个锚标记,我将活动选项卡的背景颜色更改为红色,默认颜色为黄色。
- 当活动路由为“/”时,主页选项卡变为红色 - 确定
- 当我单击“/page1”时,主页选项卡和第 1 页都变红了,为什么?我只有第 1 页标签变为红色。
这里是代码sn-ps
const routes: Routes = [
{ path: 'page1', component: Page1Component },
{ path: '', component: HomeComponent },
{ path: '**', redirectTo: '' }
];
<a routerLink="/" [routerLinkActive]="['active-tab']">Home</a>
<a routerLink="/page1" [routerLinkActive]="['active-tab']">Page 1</a>
<router-outlet></router-outlet>
a{
padding: 10px;
background: yellow;
}
a.active-tab{
background: red;
}
这里是the stackblitz code of the issue 当点击 /page2 route 时,您可以看到两个选项卡都处于活动状态。
我尝试了解决方案
<a routerLink="/" [routerLinkActive]="['active-tab']" [routerLinkActiveOptions]="{exact: true}"> Home </a>
但是当我使用查询参数(http://localhost:4200/?myParam=5)访问主路由时,主选项卡没有被激活。
【问题讨论】:
标签: angular angular8 angular-router