Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
How Could I redirect login page using Javascript
const RequireAuth = ({ children }) => {
    const [user, loading, error] = useAuthState(auth);

    const location = useLocation();
    if (loading) {
        return <Loading></Loading>
    }
    if (!user) {
        return <Navigate to="/login" state={{ from: location }} replace />;
    }
    return children;
};

export default RequireAuth;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can also do something like this:

if (!user) {
   window.location.href = `http://localhost:3000/login?from=${location}` // for example
}

and then parse query string to get a value of location


UPDATE:

Doing "routing" as I mentioned above is wrong and it will lead to hard to debug bugs. Use useNavigate hook from react-router-dom instead: https://reactrouter.com/docs/en/v6/hooks/use-navigate

about 4 years ago · Juan Pablo Isaza Denunciar

0

const [user, loading] = use Auth State(auth)
const location = use Location()

if (loading) {
    return <Loading></Loading>
}
if (!user) {
    return <Navigate to="/login" state={{ from: location }} replace ></Navigate>
}
return children

};

export default Private Route;

(sorry for space)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda