Home > Blockchain >  How to use div like link to redirect to another page?
How to use div like link to redirect to another page?

Time:05-03

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 ?

CodePudding user response:

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={naviagate("/home")}>Link </div>)
}
  • Related