+ 1

Attempted import error: 'Redirect' is not exported from 'react-router' (imported as 'Redirect').

function PrivateRoute({ children, ...routeProps }) { const profile = false; if (!profile) { return <Redirect to="/" />; } return <Route {...routeProps}>{children}</Route>; }

12th Nov 2022, 3:58 AM
Asha
Asha - avatar
1 Réponse
+ 1
Redirect has been removed from v6. You can replace Redirect with Navigate. If you want to use Redirect component, you will have to use react router version 5. Alternatively, you can use Navigate component from react router v6. A <Navigate> element changes the current location when it is rendered import { Navigate } from "react-router-dom"; return ( <Navigate to="/dashboard" replace={true} /> ) Note: Navigate is a component wrapper around useNavigate hook. You can use this hook to change routes programmatically.
12th Nov 2022, 4:00 AM
Asha
Asha - avatar