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

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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