Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent super.transitionTo() call when Cmd+Click is used #482

Merged
merged 2 commits into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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