Por favor, ayúdenme a lidiar con este error Intento de error de importación: 'Navegar' no se exporta desde 'react-router-dom' mi versión de react-router-dom es 4.1.1 Por favor, no me digan cómo actualizar a 5v o v6 porque En esas versiones, me enfrento a muchos errores, así que por favor explique cómo solucionar este error en la versión 4.1.1 de react-router-dom. El error es Intento de error de importación: 'Navegar' no se exporta desde 'react-router-dom'. todos ustedes también pueden ver la img del error
import { Navigate, useLocation } from "react-router-dom"; import { useAppSelector } from "../app/hooks"; export function PrivateRoute({ children }: { children: JSX.Element }) { const { isAuthenticated } = useAppSelector((state) => state.auth); const location = useLocation(); return isAuthenticated ? ( children ) : ( <Navigate to="/login" state={{ from: location }} /> ); }
Intente reemplazar Navigate con Link.
import { Link, useLocation } from "react-router-dom"; ... <Link to "/login" state={{ from: location }} />
Use Redirigir en lugar de Navegar en la versión 4, así
import { Redirect, useLocation } from "react-router-dom"; import { useAppSelector } from "../app/hooks"; export function PrivateRoute({ children }: { children: JSX.Element }) { const { isAuthenticated } = useAppSelector((state) => state.auth); const location = useLocation(); return isAuthenticated ? ( children ) : ( <Redirect to="/login" state={{ from: location }} /> ); }