close

[Solved] Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’

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?

  1. 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 Replaced  Navigate so Just Use Navigate instead of Redirect. Here is my example: Navigate to=”/your_path” Now, your error must be solved. Thank You.

  2. 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 Replaced  Navigate 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

Leave a Comment