I am facing the following error: Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’ in ReactJS. We are going to Learn about All Possible Solutions So Lets Get Start with This Article.
How Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’ Error Occurs?
I am facing the following error:
Attempted import error: 'Redirect' is not exported from 'react-router-dom'.
So here I am writing all the possible solutions that I have tried to resolve this error.
How To Solve Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’ Error?
- How To Solve Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’ Error?
To Solve Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’ Error If You are using react-router-dom v6 Redirect component has been removed from the react-router version 6 and
Redirect
is ReplacedNavigate
so Just Use Navigate instead of Redirect. Here is my example: Navigate to=”/your_path” Now, your error must be solved. Thank You. - Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’
To Solve Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’ Error If You are using react-router-dom v6 Redirect component has been removed from the react-router version 6 and
Redirect
is ReplacedNavigate
so Just Use Navigate instead of Redirect. Here is my example: Navigate to=”/your_path” Now, your error must be solved. Thank You.
Solution 1: Replace Redirect
with Navigate
If You are using react-router-dom v6 Redirect component has been removed from the react-router version 6 and Redirect
is Replaced Navigate
so Just Use Navigate instead of Redirect. Here is my example.
import { Navigate } from 'react-router-dom';
{ component: () => <Navigate to="/your_path" /> }
Another example.
import { Navigate } from "react-router-dom";
return (
<Navigate to="/dashboard" replace={true} />
)
Now, your error must be solved. Thank You.
Summary
It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
- Attempted import error: ‘useHistory’ is not exported from ‘react-router-dom’
- Module not found: Can’t resolve ‘web-vitals’
- Module not found: Can’t resolve ‘@mui/icons-material/FileDownload’
- Module.createRequire is not a function
- npm ERR! code ENOLOCAL npm ERR! Could not install from “@mui\material\utils” as it does not contain a package.json file