【发布时间】:2019-11-22 12:01:54
【问题描述】:
我有一个 ion-tab 具有不同的重定向方式:通过 tabs.module.ts 的路由和 html 中的 [routerLink]。
问题是:当点击ion-tab-buttons 时,它们可以正确导航到其他页面,但颜色仅在使用 Routes 和“loadchildren”路由时才会改变。
使用 CSS:
ion-tab-button {
--color-selected: var(--ion-color-text-secondary);
}
我尝试在所有选项卡中使用loadChildren 路由,但某些选项卡将重定向到组件并且没有成功。
我还尝试在 CSS 中使用伪类,例如
ion-tab-button:active {
color: blue;
}
实际文件:
tabs.page.html
<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="home">
<i class="fal fa-home-alt fa-2x"></i>
</ion-tab-button>
<ion-tab-button [routerLink]="['/tabs/home/feed/feed-user/' + id]">
<i class="fal fa-user-circle fa-2x"></i>
</ion-tab-button>
<ion-tab-button [routerLink]="['/tabs/home/trade-room']">
<i class="fal fa-comments-alt-dollar fa-2x"></i>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
tabs.module.ts
const routes: Routes = [
{
path: '',
component: TabsPage,
children: [
{
path: '',
redirectTo: '/tabs/home',
pathMatch: 'full'
},
{
path: 'home',
loadChildren: '../home/home.module#HomePageModule'
},
]
}
];
我需要一些方法来更改单击按钮时的颜色
【问题讨论】:
-
当我将动态参数添加到选项卡时,我遇到了同样的错误,因此选项卡类和值将取决于参数。我使用@Rich Tillis 的解决方案来解决我的问题。