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

[BUG] I can't prevent navigate behaviour of link #2452

Open
eleviven opened this issue Jan 25, 2023 · 0 comments
Open

[BUG] I can't prevent navigate behaviour of link #2452

eleviven opened this issue Jan 25, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@eleviven
Copy link

Describe the bug
I have added onClick prop to link to prevent navigate behaviour. It's not possible. In some cases we need to prevent it's navigate behaviour and add middleware to navigate route. We can use normal html link with useNavigate hook but in this case prefetch functionality of link is not working.

Expected behaviour
When we add onClick or other listeners as a prop, it should possible to prevent it's behaviours.

Code

const Navigate: React.FC<NavigateProps> = ({ children, ...props }) => {
  const navigate = useNavigate();

  const { fadeOut } = useContext(TransitionLayoutContext) || {};

  const handleClick = (e: MouseEvent<HTMLAnchorElement>) => {
    e.preventDefault();
    e.stopPropagation();

    fadeOut?.({
      onComplete() {
        navigate(props.to);
      },
    });
  };

  return (
    <Link onClick={handleClick} {...props}>
      {children}
    </Link>
  );
};
  • Hydrogen version 1.6.5
  • Node version 16.18.0
  • Device details Mac OS Ventura, M1 2020
@eleviven eleviven added the bug Something isn't working label Jan 25, 2023
@eleviven eleviven changed the title [BUG] We can't prevent navigate behaviour of link [BUG] I can't prevent navigate behaviour of link Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant