- Forums
- react
- React Navigate Three Ways Of Routing: href, onClick() and Link to
This Page Contains information about React Navigate Three Ways Of Routing: href, onClick() and Link to By cathy in category react with 0 Replies. [5188], Last Updated: Mon Jun 24, 2024
cathy
Tue Aug 22, 2023
0 Comments
242 Visits
These are three ways you can navigate in your React Application.
Note: <Link to="/link"> seems the fastest to me.
To use these, you will first need your imports:
Imports
import { Link, useNavigate } from "react-router-dom";
Initialize navigate()
const navigate = useNavigate();
Usage
href=""
<a href={`/tasks/user/${user.id}`} className="btn btn-primary">href</a>
OnClick()
<b onClick={()=>{navigate(`/tasks/user/${user.id}`)}}>onclick: navigate</b>
<Link>
<Link to={`/tasks/user/${user.id}`} className={`btn btn-warning`}>Edit Tasks: Link</Link>