fix(router): default exact to false in routerLinkActiveOptions

This commit is contained in:
vsavkin 2016-06-24 12:02:14 -07:00
parent 9f978cf49d
commit 1a145ac500
2 changed files with 16 additions and 13 deletions

View File

@ -24,7 +24,7 @@ export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit
private classes: string[] = []; private classes: string[] = [];
private subscription: Subscription; private subscription: Subscription;
@Input() private routerLinkActiveOptions: RouterLinkActiveOptions = {exact: true}; @Input() private routerLinkActiveOptions: RouterLinkActiveOptions = {exact: false};
/** /**
* @internal * @internal

View File

@ -860,7 +860,7 @@ describe('Integration', () => {
}); });
describe('routerActiveLink', () => { 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( fakeAsync(inject(
[Router, TestComponentBuilder, Location], [Router, TestComponentBuilder, Location],
(router: Router, tcb: TestComponentBuilder, location: 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); 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'); const native = fixture.debugElement.nativeElement.querySelector('a');
expect(native.className).toEqual('active'); expect(native.className).toEqual('active');
@ -891,7 +891,7 @@ describe('Integration', () => {
expect(native.className).toEqual(''); 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( fakeAsync(inject(
[Router, TestComponentBuilder, Location], [Router, TestComponentBuilder, Location],
(router: Router, tcb: TestComponentBuilder, location: 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); 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'); const native = fixture.debugElement.nativeElement.querySelector('link-parent');
expect(native.className).toEqual('active'); expect(native.className).toEqual('active');
@ -922,7 +922,7 @@ describe('Integration', () => {
expect(native.className).toEqual(''); 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( fakeAsync(inject(
[Router, TestComponentBuilder, Location], [Router, TestComponentBuilder, Location],
(router: Router, tcb: TestComponentBuilder, location: 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); 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'); const native = fixture.debugElement.nativeElement.querySelector('a');
expect(native.className).toEqual('active'); expect(native.className).toEqual('active');
@ -988,18 +988,21 @@ class AbsoluteLinkCmp {
class DummyLinkCmp { class DummyLinkCmp {
private exact: boolean; private exact: boolean;
constructor(route: ActivatedRoute) { constructor(route: ActivatedRoute) {
// convert 'false' into false this.exact = (<any>route.snapshot.params).exact === 'true';
this.exact = (<any>route.snapshot.params).exact !== 'false';
} }
} }
@Component({ @Component({
selector: 'link-cmp', selector: 'link-cmp',
template: template:
`<router-outlet></router-outlet><link-parent routerLinkActive="active"><a [routerLink]="['./']">link</a></link-parent>`, `<router-outlet></router-outlet><link-parent routerLinkActive="active" [routerLinkActiveOptions]="{exact: exact}"><a [routerLink]="['./']">link</a></link-parent>`,
directives: ROUTER_DIRECTIVES directives: ROUTER_DIRECTIVES
}) })
class DummyLinkWithParentCmp { class DummyLinkWithParentCmp {
private exact: boolean;
constructor(route: ActivatedRoute) {
this.exact = (<any>route.snapshot.params).exact === 'true';
}
} }
@Component({ @Component({