diff --git a/modules/@angular/router/src/directives/router_link_active.ts b/modules/@angular/router/src/directives/router_link_active.ts index f6161a2d4f..65cebbdae8 100644 --- a/modules/@angular/router/src/directives/router_link_active.ts +++ b/modules/@angular/router/src/directives/router_link_active.ts @@ -24,7 +24,7 @@ export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit private classes: string[] = []; private subscription: Subscription; - @Input() private routerLinkActiveOptions: RouterLinkActiveOptions = {exact: true}; + @Input() private routerLinkActiveOptions: RouterLinkActiveOptions = {exact: false}; /** * @internal diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index 108b633bfe..7140ce7f1d 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -860,7 +860,7 @@ describe('Integration', () => { }); describe('routerActiveLink', () => { - it('should set the class when the link is active (exact = true)', + it('should set the class when the link is active', fakeAsync(inject( [Router, TestComponentBuilder, Location], (router: Router, tcb: TestComponentBuilder, location: Location) => { @@ -878,9 +878,9 @@ describe('Integration', () => { }] }]); - router.navigateByUrl('/team/22/link'); + router.navigateByUrl('/team/22/link;exact=true'); advance(fixture); - expect(location.path()).toEqual('/team/22/link'); + expect(location.path()).toEqual('/team/22/link;exact=true'); const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.className).toEqual('active'); @@ -891,7 +891,7 @@ describe('Integration', () => { expect(native.className).toEqual(''); }))); - it('should set the class on a parent element when the link is active (exact = true)', + it('should set the class on a parent element when the link is active', fakeAsync(inject( [Router, TestComponentBuilder, Location], (router: Router, tcb: TestComponentBuilder, location: Location) => { @@ -909,9 +909,9 @@ describe('Integration', () => { }] }]); - router.navigateByUrl('/team/22/link'); + router.navigateByUrl('/team/22/link;exact=true'); advance(fixture); - expect(location.path()).toEqual('/team/22/link'); + expect(location.path()).toEqual('/team/22/link;exact=true'); const native = fixture.debugElement.nativeElement.querySelector('link-parent'); expect(native.className).toEqual('active'); @@ -922,7 +922,7 @@ describe('Integration', () => { expect(native.className).toEqual(''); }))); - it('should set the class when the link is active (exact = false)', + it('should set the class when the link is active', fakeAsync(inject( [Router, TestComponentBuilder, Location], (router: Router, tcb: TestComponentBuilder, location: Location) => { @@ -940,9 +940,9 @@ describe('Integration', () => { }] }]); - router.navigateByUrl('/team/22/link;exact=false'); + router.navigateByUrl('/team/22/link'); advance(fixture); - expect(location.path()).toEqual('/team/22/link;exact=false'); + expect(location.path()).toEqual('/team/22/link'); const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.className).toEqual('active'); @@ -988,18 +988,21 @@ class AbsoluteLinkCmp { class DummyLinkCmp { private exact: boolean; constructor(route: ActivatedRoute) { - // convert 'false' into false - this.exact = (route.snapshot.params).exact !== 'false'; + this.exact = (route.snapshot.params).exact === 'true'; } } @Component({ selector: 'link-cmp', template: - `link`, + `link`, directives: ROUTER_DIRECTIVES }) class DummyLinkWithParentCmp { + private exact: boolean; + constructor(route: ActivatedRoute) { + this.exact = (route.snapshot.params).exact === 'true'; + } } @Component({