HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptreactCritical

React: 'Redirect' is not exported from 'react-router-dom'

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
redirectexportedfromdomreactnotrouter

Problem

I am getting the following error when running npm run start in the terminal.

Attempted import error: 'Redirect' is not exported from 'react-router-dom'.

I have reinstalled node_modules, react-router-dom, react-router. Also restarted the terminal and my computer, but the issue persists.

My code:

import React from 'react';
import { Switch, Redirect } from 'react-router-dom';

import { RouteWithLayout } from './components';
import { Minimal as MinimalLayout } from './layouts';

import {
  Login as LoginView,
  Dashboard as DashboardView,
  NotFound as NotFoundView
} from './views';

const Routes = () => {
  return (
    
      
       }
        exact
        layout={MinimalLayout}
        path="/login"
      />
      
    
  );
};

export default Routes;


Here is my package.json imports:

"react-router": "^6.0.0-beta.0",
"react-router-dom": "^6.0.0-beta.0",

Solution

For react-router-dom v6, simply replace Redirect with Navigate

import { Navigate } from 'react-router-dom';
.
.
.
{ component: () =>  }

Code Snippets

import { Navigate } from 'react-router-dom';
.
.
.
{ component: () => <Navigate to="/404" /> }

Context

Stack Overflow Q#63690695, score: 429

Revisions (0)

No revisions yet.