A
A
AlexRayn2020-05-19 16:52:43
React
AlexRayn, 2020-05-19 16:52:43

How to add routing to div?

When a div is clicked, another div opens and the routing should change. It's clear with links - you need to specify href, but what to do here? I am using react-router-dom

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abberati, 2020-05-19
@abberati

Take react-router-dom and don't spawn bicycles.

M
Mikhail Osher, 2020-05-19
@miraage

import { useHistory } from 'react-router-dom';

const MyComponent = () => {
  const history = useHistory();

  const handleClick = () => {
    history.push('/new/route');
  };

  return <div onClick={handleClick}>hello</div>;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question