首页 > 其他 > 详细

[Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive

时间:2016-09-25 22:27:05      阅读:248      评论:0      收藏:0      [点我收藏+]

You can easily show the user which route they are on using Angular 2’s routerLinkActive. Whenever a route matches the routerLink defined on the element, then the routerLInkActive will add the class that you assign it to.

 

See Doc

 

app.component.ts:

import {Component} from @angular/core;

@Component({
  selector: app-root,
  templateUrl: ./app.component.html,
  styleUrls: [./app.component.css]
})
export class AppComponent {
  title = app works!;
}

app.component.css:

a{
  text-decoration: none;
}

a.active{
  font-weight: bold;
  color: darkred;
}

app.component.html:

<nav>
  <a [routerLink]="‘‘"
     routerLinkActive="active"
     [routerLinkActiveOptions]="{exact: true}">Home</a>
  <a
    [routerLink]="‘contact‘"
    routerLinkActive="active"
  >Contact</a>
</nav>
<router-outlet></router-outlet>

 

Github

[Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive

原文:http://www.cnblogs.com/Answer1215/p/5907095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!