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:
@ -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);
|
||||
|
Reference in New Issue
Block a user