feat(router): router-link-active CSS class support

The `[router-link]` directive now applies the `router-link-active` CSS
class to the associated element whenever the link is active.

Closes #3209
This commit is contained in:
Brian Ford
2015-08-30 21:27:11 -07:00
parent de37729823
commit 36eb9d392d
2 changed files with 110 additions and 6 deletions

View File

@ -37,7 +37,11 @@ import {Instruction, stringifyInstruction} from './instruction';
@Directive({
selector: '[router-link]',
properties: ['routeParams: routerLink'],
host: {'(^click)': 'onClick()', '[attr.href]': 'visibleHref'}
host: {
'(^click)': 'onClick()',
'[attr.href]': 'visibleHref',
'[class.router-link-active]': 'isRouteActive'
}
})
export class RouterLink {
private _routeParams: List<any>;
@ -50,6 +54,8 @@ export class RouterLink {
constructor(private _router: Router, private _location: Location) {}
get isRouteActive(): boolean { return this._router.isRouteActive(this._navigationInstruction); }
set routeParams(changes: List<any>) {
this._routeParams = changes;
this._navigationInstruction = this._router.generate(this._routeParams);