[英]How can I underline the active link in my side nav bar? Using material design in angular app
<div class="mt-3">
<mat-nav-list>
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
SERVICE
</a>
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
BILLING
</a>
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
OIL TICKETS
</a>
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
MY TIME
</a>
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
APPROVE TIME
</a>
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
EMPLOYEE LIST
</a>
snippet of my html navigation page I just want to underline the active link but not quite sure how to do that within an angular app using material design. 我的html导航页面的摘要,我只想在活动链接下划线,但不太确定如何使用材质设计在有角度的应用程序中执行此操作。 Also if there is a way to collapse it I would like to know that too.
另外,如果有一种方法可以使它崩溃,我也想知道。 Thank you.
谢谢。
As found in the Angular Routing and Navigation documentation, you use the routerLinkActive
directive. 如在Angular 路由和导航文档中
routerLinkActive
,您可以使用routerLinkActive
指令。
<mat-nav-list>
<a mat-list-item
routerLink="/paycard"
routerLinkActive="active_route"> Paycard </a>
</mat-nav-list>
This will add the .active_route
class to your active route. 这会将
.active_route
类添加到您的活动路由中。 Then you can style it as you'd like: 然后,您可以根据需要设置其样式:
.active_route {
text-decoration: underline;
}
If you have similar links, you may need to use {pathMatch: full}
in the router link options (eg if you have routes "/pay" and "/pay/card".) 如果您具有类似的链接,则可能需要在路由器链接选项中使用
{pathMatch: full}
(例如,如果您的路由为“ / pay”和“ / pay / card”。)
If you do the routing in the tag you can add the routerLinkActive
attribute to apply a css class when the route is active. 如果您在标记中进行路由,则可以添加
routerLinkActive
属性,以在路由处于活动状态时应用css类。
In you case the would look something like this: 在您的情况下,将如下所示:
<a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'
routerLink="service" routerLinkActive="<css class you want to apply when active"> SERVICE </a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.