简体   繁体   中英

React Hooks <a onClick> modal

I have a functional react component using hooks. I want to show a modal after clicking the a tag before redirecting. I tried useHistory to push the route but it does not work. Here is a reduced version of my code

const LoginPage = ({ url }) => {
  const handleClick= (e) => {
    e.preventDefault;
    showModal();
    // trigger the redirect after closing the modal
  };

  return (
    <a
      href={url}
      onClick={(e) => handleClick(e)}
    >
      click
    </a>
  );
};

You can definitely do that with an history push in the onCloseWhatever of your modal

If it's not working you should check your implementation of history

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM