From 63f023bb09b3b93a03af988cedea392cce75cb61 Mon Sep 17 00:00:00 2001 From: Jelle Oppenhuis Date: Mon, 5 Feb 2024 13:26:07 +0100 Subject: [PATCH] Use default click handler when target is not _self and keyboard modifier is used in RouterLinkDelegateDirective --- .../navigation/router-link-delegate.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/angular/common/src/directives/navigation/router-link-delegate.ts b/packages/angular/common/src/directives/navigation/router-link-delegate.ts index d996d739428..ce372f34c68 100644 --- a/packages/angular/common/src/directives/navigation/router-link-delegate.ts +++ b/packages/angular/common/src/directives/navigation/router-link-delegate.ts @@ -49,6 +49,29 @@ export class RouterLinkDelegateDirective implements OnInit, OnChanges { */ @HostListener('click', ['$event']) onClick(ev: UIEvent): void { + /** + * Using a target different from _self will + * open another browser tab. + * Therefore, use default + * behaviour of this event. + */ + if (this.elementRef.nativeElement.target === undefined || this.elementRef.nativeElement.target !== '_self') { + return; + } + + /** + * Using a keyboard modifier will + * open another browser tab. + * Therefore, use default + * behaviour of this event. + */ + if ( + (ev instanceof MouseEvent || ev instanceof TouchEvent) + && (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) + ) { + return; + } + this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation); /**