TylerBarnes / gatsby-plugin-transition-link

A link component for page transitions in gatsby
537 stars 71 forks source link

Link not working with "preventDefault" in an onClick handler #219

Open alec-francis opened 4 years ago

alec-francis commented 4 years ago

Hi all,

When a user clicks on a link, it would be great if there was a way to cancel the transition. (My use case is a reminder for users to save their work before navigating away from the page.)

This is similar to what I've been using successfully in the past with gatsby-link. (Rather than call preventDefault straightaway, I first check to see if any changes have not being saved.)

<Link
  to="/example-page/"
  onClick={evt => evt.preventDefault()}
>
  Example Link
</Link>

I've been trying to get this working with this package but haven't had any luck. Does anyone know if this is possible?

Cheers,

Alec

UPDATE: I did some debugging. It looks like preventDefault method is only called after shouldNavigate has already executed in TransitionLink.js As such, the page transition has already occurred by the time the halt is requested.

polyrhythmatic commented 3 years ago

I'm having this issue as well - is there any movement on this or a workaround?

pacocom commented 2 years ago

I have the same issue! Please tell me how to solve it. Thanks.