diff --git a/goldens/public-api/router/router.d.ts b/goldens/public-api/router/router.d.ts index 58fda6ec47..f2342df428 100644 --- a/goldens/public-api/router/router.d.ts +++ b/goldens/public-api/router/router.d.ts @@ -380,7 +380,7 @@ export declare class RouterLink { }; queryParamsHandling: QueryParamsHandling; replaceUrl: boolean; - set routerLink(commands: any[] | string); + set routerLink(commands: any[] | string | null | undefined); skipLocationChange: boolean; state?: { [k: string]: any; @@ -414,7 +414,7 @@ export declare class RouterLinkWithHref implements OnChanges, OnDestroy { }; queryParamsHandling: QueryParamsHandling; replaceUrl: boolean; - set routerLink(commands: any[] | string); + set routerLink(commands: any[] | string | null | undefined); skipLocationChange: boolean; state?: { [k: string]: any; diff --git a/packages/router/src/directives/router_link.ts b/packages/router/src/directives/router_link.ts index a6462ce08e..e3c5a072a7 100644 --- a/packages/router/src/directives/router_link.ts +++ b/packages/router/src/directives/router_link.ts @@ -139,7 +139,7 @@ export class RouterLink { } @Input() - set routerLink(commands: any[]|string) { + set routerLink(commands: any[]|string|null|undefined) { if (commands != null) { this.commands = Array.isArray(commands) ? commands : [commands]; } else { @@ -229,7 +229,7 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy { } @Input() - set routerLink(commands: any[]|string) { + set routerLink(commands: any[]|string|null|undefined) { if (commands != null) { this.commands = Array.isArray(commands) ? commands : [commands]; } else { diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index b6882f5c6d..f6d8bad78c 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -1821,11 +1821,15 @@ describe('Integration', () => { expect(native.getAttribute('href')).toEqual('/home'); })); - it('should not throw when commands is null', fakeAsync(() => { + it('should not throw when commands is null or undefined', fakeAsync(() => { @Component({ selector: 'someCmp', - template: - `Link` + template: ` + Link + + Link + + ` }) class CmpWithLink { } @@ -1835,10 +1839,12 @@ describe('Integration', () => { let fixture: ComponentFixture = createRoot(router, CmpWithLink); router.resetConfig([{path: 'home', component: SimpleCmp}]); - const anchor = fixture.nativeElement.querySelector('a'); - const button = fixture.nativeElement.querySelector('button'); - expect(() => anchor.click()).not.toThrow(); - expect(() => button.click()).not.toThrow(); + const anchors = fixture.nativeElement.querySelectorAll('a'); + const buttons = fixture.nativeElement.querySelectorAll('button'); + expect(() => anchors[0].click()).not.toThrow(); + expect(() => anchors[1].click()).not.toThrow(); + expect(() => buttons[0].click()).not.toThrow(); + expect(() => buttons[1].click()).not.toThrow(); })); it('should update hrefs when query params or fragment change', fakeAsync(() => {