Reputation: 189
When trying to import useNavigate
from react-router-dom
, I get the following error:
Attempted import error: 'useNavigate' is not exported from 'react-router-dom'.
My Import statement:
import { useNavigate } from 'react-router-dom';
Upvotes: 15
Views: 61927
Reputation: 155
If you're using react router v5 you can use useHistory.
import { useHistory } from "react-router-dom";
use:
history.push('/your-component')
Upvotes: 12
Reputation: 27
I faced issue as like this: "useNavigate is not exported from 'react-router-dom"
My solution - I uninstalled the react-router-dom and I have reinstalled it... now this issue is resolved for me..
Upvotes: 3
Reputation: 2502
You are trying to use the latest features of react-router
.
Please make sure that you installed the [email protected]
.
It is React Router v6 which gives you a useNavigate hook
Please refer here for further reading from the React Router team
Two quick ways to check the version:
package.json
filenpm list --depth=0
to view the various packages in your projectUpvotes: 14