1

I need to make div which will act simulate to Link element, so when you click on it you navigate to another page.

Something like this

<Link to="/employees">
   ...  
</Link>

But it has to be div.

I could use onClick but when I use it, I should use whole path https://pro.websire.com/employees. I don't want to use it because we have different versions of website.

So path should be exactly like in Link element

<div onClick={to('/employees')}>
  ...
</div>

Does anyone know is it possible to do ?

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
Karina Shulan
  • 161
  • 1
  • 9

1 Answers1

3

If you are using react router, you can programmatically navigate using the useNavigate hook. Inside your component, you need to do the following.

const LinkComponent = () =>{
    const navigate = useNavigate()
    return(<div onClick={() => navigate("/home")}>Link </div>)
}
Arky Asmal
  • 1,162
  • 4
  • 10