Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!