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

216
Views
¿Cómo escuchar el cambio de URL de la página sin actualizar la página en reaccionar?

Tengo algunas migas de pan en la página. Cuando reemplazoEstado, veo que la URL cambia, no hay problema con eso, pero no pude detectar ese cambio de URL en el componente de reacción que probé, pero no tiene sentido que funcione solo una vez cuando el componente está montado.

 const usePath = () => { const [path, pathSet] = useState(window.location.pathname); const listenToPopstate = () => { const winPath = window.location.pathname; pathSet(winPath); }; useEffect(() => { window.addEventListener("locationchange", listenToPopstate); return () => { window.removeEventListener("locationchange", listenToPopstate); }; }, []); return path; }; const Breadcrumb = () => { const [state, stateSet] = useState(false); const path = usePath(); useEffect(() => { path.indexOf('StoreSelection') > -1 && stateSet(true) }, [path]); return ( <ol className="breadcrumb" style={breadcrumb}> <li key="1" className="breadcrumb-item align-items-center"> {state ? 'AAA' : 'BBB'} </li> </ol> ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que encontrará que instanciar un objeto de history y usarlo para escuchar será más fácil para usted.

historia

 import { createBrowserHistory } from 'history'; const history = createBrowserHistory(); const usePath = () => { const [path, pathSet] = useState(history.location.pathname); const listener = (location, action) => { pathSet(location.pathname); }; useEffect(() => { const unlisten = history.listen(listener); return unlisten; }, []); return path; };
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!