diff --git a/packages/router/src/directives/router_link.ts b/packages/router/src/directives/router_link.ts index fcc1fa753c..86fb3645e1 100644 --- a/packages/router/src/directives/router_link.ts +++ b/packages/router/src/directives/router_link.ts @@ -111,7 +111,7 @@ import {UrlTree} from '../url_tree'; * * @publicApi */ -@Directive({selector: ':not(a)[routerLink]'}) +@Directive({selector: ':not(a):not(area)[routerLink]'}) export class RouterLink { // TODO(issue/24571): remove '!'. @Input() queryParams !: {[k: string]: any}; @@ -191,7 +191,7 @@ export class RouterLink { * * @publicApi */ -@Directive({selector: 'a[routerLink]'}) +@Directive({selector: 'a[routerLink],area[routerLink]'}) export class RouterLinkWithHref implements OnChanges, OnDestroy { // TODO(issue/24571): remove '!'. @HostBinding('attr.target') @Input() target !: string; diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index b920faa984..aa8dbbdc60 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -1939,6 +1939,25 @@ describe('Integration', () => { expect(history[history.length - 1].state) .toEqual({foo: 'bar', navigationId: history.length}); }))); + + it('should set href on area elements', fakeAsync(() => { + @Component({ + selector: 'someRoot', + template: `` + }) + class RootCmpWithArea { + } + + TestBed.configureTestingModule({declarations: [RootCmpWithArea]}); + const router: Router = TestBed.get(Router); + + const fixture = createRoot(router, RootCmpWithArea); + + router.resetConfig([{path: 'home', component: SimpleCmp}]); + + const native = fixture.nativeElement.querySelector('area'); + expect(native.getAttribute('href')).toEqual('/home'); + })); }); describe('redirects', () => {