export 'usehistory' (imported as 'usehistory') was not found in 'react-router-dom'
You may face export 'usehistory' (imported as 'usehistory') was not found in 'react-router-dom error because of wrong react-router-dom
version.
You can easily fix this error by correcting react-router-dom
version.
You can follow below instrutions to solve export 'usehistory' (imported as 'usehistory') was not found in 'react-router-dom' error.
Instructions
- go to
package.json
file - check
react-router-dom
package version. - if version is 5 or less then its incorrect version use v6 or above
- use command in terminal
npm i [email protected]
oryarn add [email protected]
- once you insatll latest package, you can use
useNavigate
instead ofusehistory
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate('/home');
this is the latest way to navigate website pages.
Related Articles
- Import statement and Babel
- should I choose reactjs+f7 or f7+vue.js?
- Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- .tsx webpack compile fails: Unexpected token <
- React-router: Passing props to children
- ListView.DataSource looping data for React Native
- React Native with visual studio 2015 IDE