Skip to content

Commit

Permalink
fix: prevent super.transitionTo() call when Cmd+Click is used (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored Nov 27, 2020
1 parent 2a790ef commit 44a4c45
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions addon/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default class Link {
* Transition into the target route.
*/
@action
transitionTo(): Transition {
transitionTo(): Transition | undefined {
assert(
'You can only call `transitionTo`, when the router is initialized, e.g. when using `setupApplicationTest`.',
this._linkManager.isRouterInitialized
Expand All @@ -242,7 +242,7 @@ export default class Link {
* possible.
*/
@action
replaceWith(): Transition {
replaceWith(): Transition | undefined {
assert(
'You can only call `replaceWith`, when the router is initialized, e.g. when using `setupApplicationTest`.',
this._linkManager.isRouterInitialized
Expand Down Expand Up @@ -272,8 +272,7 @@ export class UILink extends Link {
private preventDefault(event?: Event | unknown) {
if (
(this._params.preventDefault ?? true) &&
typeof (event as Event)?.preventDefault === 'function' &&
(!isMouseEvent(event) || isUnmodifiedLeftClick(event))
typeof (event as Event)?.preventDefault === 'function'
) {
(event as Event).preventDefault();
}
Expand All @@ -285,7 +284,9 @@ export class UILink extends Link {
* Optionally call `preventDefault()`, if an `Event` is passed in.
*/
@action
transitionTo(event?: Event | unknown): Transition {
transitionTo(event?: Event | unknown): Transition | undefined {
if (isMouseEvent(event) && !isUnmodifiedLeftClick(event)) return;

// Intentionally putting this *before* the assertion to prevent navigating
// away in case of a failed assertion.
this.preventDefault(event);
Expand All @@ -300,7 +301,9 @@ export class UILink extends Link {
* Optionally call `preventDefault()`, if an `Event` is passed in.
*/
@action
replaceWith(event?: Event | unknown): Transition {
replaceWith(event?: Event | unknown): Transition | undefined {
if (isMouseEvent(event) && !isUnmodifiedLeftClick(event)) return;

// Intentionally putting this *before* the assertion to prevent navigating
// away in case of a failed assertion.
this.preventDefault(event);
Expand Down

0 comments on commit 44a4c45

Please sign in to comment.