Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

history.push not working open in new tab in react

I am new to react js and I am a self-learner. I need to pass some data with my react route and access this data on another side…So I used useHistory() hook to accomplish my task. But now I have some errors. I can only route with mouse click event only. I can’t route using open in new tab or my mouse wheel. I have no idea what’s going on with my code. So Anyone can help me with that…Thank you.

  const sendPixelData = () => {
    history.push({
      pathname: `product/${product._id}`,
      state: { detail: product },
    });
  };


 <Link onClick={sendPixelData}> Do some logic and other thing  </Link>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A Link component from react-router should not have an onClick parameter but follow the props needed according to the documentation:

https://v5.reactrouter.com/web/api/Link

If you want to pass data you can use the following syntax:

<Link
  to={{
  pathname: `product/${product._id}`,
  state: { detail: product },
  }}
/>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading