Ar26
Ar26

Reputation: 1099

React redirect - Redirect component on react-router-dom

I'm trying to build a simple component that will make one API call and after 2 seconds will redirect to another page. For that, I tried to use the Redirect component from react-router-dom, but the import fails

import { Redirect } from "react-router-dom"

I'm getting the error: "react-router-dom has no exported member 'Redirect'."

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

Upvotes: 2

Views: 1274

Answers (1)

tmhao2005
tmhao2005

Reputation: 17474

It looks like the <Redirect /> in v5 has been replaced by <Navigate /> which can also be used in the same way.

import { Navigate } from 'react-router-dom';

function App() {
  return <Navigate to="/home" />;
}

Upvotes: 5

Related Questions