Skip to content

Commit

Permalink
fix(angular): routerLink allows opening in a new tab for link elements (
Browse files Browse the repository at this point in the history
#25014)

Resolves #24413

Co-authored-by: Julian Pfeil <5290648+Juarrow@users.noreply.github.com>
  • Loading branch information
sean-perkins and Juarrow committed Mar 31, 2022
1 parent e8fc4ec commit b010f07
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions angular/src/directives/navigation/router-link-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { AnimationBuilder, RouterDirection } from '@ionic/core';

import { NavController } from '../../providers/nav-controller';

/**
* Adds support for Ionic routing directions and animations to the base Angular router link directive.
*
* When the router link is clicked, the directive will assign the direction and
* animation so that the routing integration will transition correctly.
*/
@Directive({
selector: '[routerLink]',
})
Expand All @@ -31,19 +37,15 @@ export class RouterLinkDelegateDirective implements OnInit, OnChanges {
this.updateTargetUrlAndHref();
}

@HostListener('click')
onClick(): void {
this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation);
}

private updateTargetUrlAndHref() {
if (this.routerLink?.urlTree) {
const href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.routerLink.urlTree));
this.elementRef.nativeElement.href = href;
}
}

/**
* @internal
*/
@HostListener('click', ['$event'])
onClick(ev: UIEvent): void {
this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation);
ev.preventDefault();
}
}

1 comment on commit b010f07

@danielehrhardt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b010f07#diff-ddccb39fd69c03734ed6d392993f4cd4308e32589fe53a2e5d29e0e7bb552743L47
Since you removed that line the Browser does a refresh on routerlink clic.

Please sign in to comment.