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

100
Vistas
Conditional routing ReactJS according to date

I'm building a website in ReactJS that allows users to fill out a form during the weekday but redirects to a closed page on the weekend. How would I conditionally route to a different page using react-router-dom? I'd also like it to not be local time, but according to, say, PST. Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Without knowing your exact router setup, I can only guess, but here are some ideas:

  1. The useNavigate hook:

     import { useNavigate } from "react-router-dom";
    
     const navigate = useNavigate();
    
     // check the current date, based on locale 
     useEffect(() => {
        // date-checking logic
        // if(weekday) { navigate('/weekday/specific/page'); }
        // if(weekend) { navigate('/weekend/specific/page'); }
        // else navigate('/wherever')
     }, []);
    
    

Note the use of useEffect, you want the logic to be checked upon mounting the component that decides whether the redirect should be performed or not.

  1. <Redirect /> component:

     import { Redirect, Route } from 'react-router-dom';
     // const weekday = (date checking logic)
     <Route exact path="/">
       {weekday ? <Redirect to="/weekday" /> : <Weekend />}
     </Route>
    
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