fix(router): router link active should take all descendants into account
This commit is contained in:
parent
93a4ca652a
commit
8d90a5a4cf
@ -59,8 +59,9 @@ import {RouterLink, RouterLinkWithHref} from './router_link';
|
|||||||
*/
|
*/
|
||||||
@Directive({selector: '[routerLinkActive]'})
|
@Directive({selector: '[routerLinkActive]'})
|
||||||
export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit {
|
export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit {
|
||||||
@ContentChildren(RouterLink) links: QueryList<RouterLink>;
|
@ContentChildren(RouterLink, {descendants: true}) links: QueryList<RouterLink>;
|
||||||
@ContentChildren(RouterLinkWithHref) linksWithHrefs: QueryList<RouterLinkWithHref>;
|
@ContentChildren(RouterLinkWithHref, {descendants: true})
|
||||||
|
linksWithHrefs: QueryList<RouterLinkWithHref>;
|
||||||
|
|
||||||
private classes: string[] = [];
|
private classes: string[] = [];
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
|
@ -1237,8 +1237,9 @@ describe('Integration', () => {
|
|||||||
children: [{
|
children: [{
|
||||||
path: 'link',
|
path: 'link',
|
||||||
component: DummyLinkWithParentCmp,
|
component: DummyLinkWithParentCmp,
|
||||||
children:
|
children: [
|
||||||
[{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
|
{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}
|
||||||
|
]
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
@ -1439,17 +1440,6 @@ class DummyLinkCmp {
|
|||||||
constructor(route: ActivatedRoute) { this.exact = (<any>route.snapshot.params).exact === 'true'; }
|
constructor(route: ActivatedRoute) { this.exact = (<any>route.snapshot.params).exact === 'true'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'link-cmp',
|
|
||||||
template:
|
|
||||||
`<router-outlet></router-outlet><link-parent routerLinkActive="active" [routerLinkActiveOptions]="{exact: exact}"><a [routerLink]="['./']">link</a></link-parent>`,
|
|
||||||
directives: ROUTER_DIRECTIVES
|
|
||||||
})
|
|
||||||
class DummyLinkWithParentCmp {
|
|
||||||
private exact: boolean;
|
|
||||||
constructor(route: ActivatedRoute) { this.exact = (<any>route.snapshot.params).exact === 'true'; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'link-cmp',
|
selector: 'link-cmp',
|
||||||
template: `<a [routerLink]="['../simple']">link</a>`,
|
template: `<a [routerLink]="['../simple']">link</a>`,
|
||||||
@ -1566,6 +1556,19 @@ class LinkInNgIf {
|
|||||||
alwaysTrue = true;
|
alwaysTrue = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'link-cmp',
|
||||||
|
template: `<router-outlet></router-outlet>
|
||||||
|
<link-parent routerLinkActive="active" [routerLinkActiveOptions]="{exact: exact}">
|
||||||
|
<div ngClass="{one: 'true'}"><a [routerLink]="['./']">link</a></div>
|
||||||
|
</link-parent>`,
|
||||||
|
directives: ROUTER_DIRECTIVES
|
||||||
|
})
|
||||||
|
class DummyLinkWithParentCmp {
|
||||||
|
private exact: boolean;
|
||||||
|
constructor(route: ActivatedRoute) { this.exact = (<any>route.snapshot.params).exact === 'true'; }
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'root-cmp',
|
selector: 'root-cmp',
|
||||||
template: `<router-outlet></router-outlet>`,
|
template: `<router-outlet></router-outlet>`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user