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的更多相关文章

  1. [Angular2 Router] Use Params from Angular 2 Routes Inside of Components

    Angular 2’s ActivatedRoute allows you to get the details of the current route into your components. ...

  2. [Angular2 Form] Style Validation in Angular 2 Forms

    Inputs using Angular 2’s ngModel automatically apply style classes of .ng-validand .ng-invalid each ...

  3. [Angular2 Router] Build Angular 2 Navigation with routerLink

    Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...

  4. [Angular2 Router] Resolving route data in Angular 2

    From Article: RESOLVING ROUTE DATA IN ANGULAR 2 Github If you know Anuglar UI router, you must know ...

  5. [Angular2 Router] Index router

    Index router as default router. import {RouterModule} from "@angular/router"; import {NotF ...

  6. [Angular2 Router] Setup page title with Router events

    Article import 'rxjs/add/operator/filter'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator ...

  7. 解决TS报错Property 'style' does not exist on type 'Element'

    在使用queryselector获取一个dom元素,编译时却报错说property 'style' does not exist on type 'element'. 原因:这是typescript的 ...

  8. 在Angular中使用element

    在angular中使用element 1.在一个新建的angular的项目中插入element npm i --save element-angular 2.在项目中的styles.css中插入文件, ...

  9. [Angular2 Router] Programmatic Router Navigation via the Router API - Relative And Absolute Router Navigation

    In this tutorial we are going to learn how to navigate programmatically (or imperatively) by using t ...

随机推荐

  1. DHTML 教程学习进度备忘

    书签:跳过:另外跳过的内容有待跟进 __________________ 学习资源:W3School. _________________ 跳过的内容: 1.这个学习进度和前面几个学习进度,只是学习了 ...

  2. 二.JSP开发过程中遇到的问题及解决

    一.开发环境问题 问题一:Failed to load the JNI shared library 启动Eclipse时弹出“Failed to load the JNI shared librar ...

  3. Intent传递数据

    方式比较多,先看看代码,一会儿再总结. activity_main.xml <RelativeLayout xmlns:android="http://schemas.android. ...

  4. gcc都做了什么优化

    直接上程序: setjmp和longjmp是处理函数嵌套调用的,goto语句不能跨越函数,所以不选择goto. #include <setjmp.h> int setjmp(jmp_buf ...

  5. javascript函数sort

    sort函数用于对数组的元素进行排序 语法:arrayObject.sort(sortby); 参数sortby可选,规定排序顺序,必须是函数. 如果调用该方法时没有使用参数,将按照字幕顺序进行排序, ...

  6. Python面试必须要看的15个问题

    本文由EarlGrey@编程派独家编译,转载请务必注明作者及出处. 原文:Sheena@codementor 译文:编程派 引言 想找一份Python开发工作吗?那你很可能得证明自己知道如何使用Pyt ...

  7. Hadoop的分布模式安装

      1.确定集群的结构 IP(主机名) 角色 192.168.1.220(hadoop0) NameNode.JobTracker 192.168.1.221(hadoop1) SecondaryNa ...

  8. css3 钟表

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. Linux下Python获取IP地址

    <lnmp一键安装包>中需要获取ip地址,有2种情况:如果服务器只有私网地址没有公网地址,这个时候获取的IP(即私网地址)不能用来判断服务器的位置,于是取其网关地址用来判断服务器在国内还是 ...

  10. MyEclipse中消除frame引起的“the file XXX can not be found.Please check the location and try again.”的错误

    读者如要转载,请标明出处和作者名,谢谢. 地址01:http://space.itpub.net/25851087 地址02:http://www.cnblogs.com/zjrodger/ 作者名: ...