With the new, up and coming Angular 2 router (at version 3.0-alpha.7 as I write this), it's very simple.
All you need to do is use the [routerLinkActive]
directive in your link.
<a [routerLinkActive]="['active']" [routerLink]="['/contact', contact.id ]">
{{contact.name}}
</a>
This is what you will be using when Angular 2 is released for real, and no longer a release candidate. I'm using the alpha of the router now and not having any issues.
Here's Plunk demonstrating it. You can see that the links go red as you click on them. That's the directive assigning the active
class to them. You could use any class name of your choosing, of course.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…