Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
May 4, 2023
react-router-dom v6 has replaced the useHistory() with useNavigate(). Here is the usage of useNavigate.
import { useNavigate } from "react-router-dom";
Inside your functional component,
const navigate = useNavigate(); const onClick = () => { navigate(‘/path) }
Following are the relevant methods of useNavigate hook:
• Replace history.push('/path') with navigate('/path') • Replace history.replace('/path') with navigate('/path', { replace: true }) • Replace history.push({ pathname: '/path', state: yourData, }) with navigate('/path', { state: yourData })
If you’re not planning to upgrade to v6 and lots of your files are already in react-router v5 then you can try migrating to the latest minor version of v5 by
npm install react-router-dom@"<6.0.0"
Then, over time, you can migrate it to the latest version by following their official guidelines.