Home > Software design >  Button to be clicked and routed to another page in React
Button to be clicked and routed to another page in React

Time:04-28

 <button component={Link} to={"/create"}>
      <EditIcon></EditIcon>
 </button>

This is my code to make an icon a clickable button that routes to the page "create." The button is not performing any function. Can anyone help me out?

CodePudding user response:

 <Link to={"/create"}
      <EditIcon />
 </Link >

and dont forget to import it from react-router-dom

import {Link} from "react-router-dom"

CodePudding user response:

import { useHistory } from "react-router-dom";
const Button = ()=>{
let history = useHistory();
return(<>
<EditIcon onClick={()=>history.push("/create");}/>
</>

)}
export default Button;

here u can learn about react router from this link

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

CodePudding user response:

`import {useNavigate} from 'react-router-dom

const navigate = useNaviagte()

<button onClick={()=>navigate("/create")}> `

  • Related