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

150
Views
how do i use react router in if/else condition in a function called by button click

const handleStartClick = () => {
    const email = localStorage.getItem('email')
    if (email !== null && email.length !== 0) {
      alert('not empty!')
    } else {
        <Routes>
          <Route path="/EmailInput" element={<EmailInput />}/>
        </Routes>
    }
  }

I want to use router in else condition to route to a different component. The function handleStartClick is called after button click.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can't.


If you want to trigger navigation from a callback:

  1. Define your route with your other routes, giving it a path
  2. Navigate to that path with the navigate function returned by the useNavigate hook

If you want to show a different component in a given context, without it being a whole new route, then set a state instead. Determine which component to show in the render function.

about 4 years ago · Juan Pablo Isaza Report

0

This is how we use if-else in jsx

 return (<Routes>
  {(email !== null && email.length !== 0)&&alert("not empty!") ||  <Route path="/EmailInput" element={<EmailInput />}/> }

</Routes>)
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!