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

188
Vistas
How to use browser history with components?

Suppose I have following code:

const [showChild1, setShowChild1] = useState(false)
const [showChild2, setShowChild2] = useState(false)

        <ParentComponent>
          {showChild1 && <Child1 />}
          {showChild1 && <Child2 />}
           ....
      </ParentComponent

Suppose I am viewing Child2 in my browser, but I want to go back to see Child1. How can I use the browser's back and forward buttons to navigate between conditionally rendered components? As of now when i click on the back button im pushed to path /.

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

0

You can add event listeners to the global window object. The event name is "popstate", here is the code example:

  useEffect(() => {
    window.history.pushState(null, null, window.location.pathname);
    window.addEventListener('popstate', yourEvent);
    return () => {
      window.removeEventListener('popstate', yourEvent);  
    };
  }, []);
about 4 years ago · Juan Pablo Isaza Denunciar

0

use onpopstate event to handle browser navigation options.

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