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

138
Views
Reaccionar sin volver a renderizar después del cambio de URL

Mi definición de ruta:

 ...{ path: '/profile/:id', component: ProfilePage }, ...

y luego el mapeo es:

 {routes.map(({ path, component }) => { return ( <Route exact key={path} path={path} component={component} /> ) })}

Si navego de */main* a */profile/3* todo está bien. Pero si ya estoy en un perfil y navego a otro perfil con una identificación diferente (*profile/3* -> *profile/5*) , comienza el problema. La URL en el navegador cambia pero el contenido no se vuelve a representar. Además, la función useEffect no se vuelve a llamar. Si navego a cualquier otra URL y luego empiezo la búsqueda de una persona, todo vuelve a estar bien. Entonces solo una segunda llamada de perfil a perfil no funciona.

Mi navegación en la lista se hace por

 const onItemSelected = (event) => { const selectedPerson = event.itemData setShowSuggestions(false) setFilteredSuggestions([]) setInput("") if(selectedPerson && selectedPerson.id) history.replace(`/profile/${selectedPerson.id}`); }

Mi useEffect en profile.js

 export default (props) => { ... useEffect(() => { try { setLoading(true) const urlPath = window.location.href.split('/') const id = urlPath[urlPath.length - 1] loadProfile(id) } catch (e) { setLoading(false) history.push("/aufgabenliste") } }, []);

También probé history.push() pero tampoco funcionó.

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

0

Encontré la solución. En primer lugar, es mucho más fácil cargar la ID desde los accesorios en lugar de acceder a window.location.href...

Y el segundo paso es configurar los accesorios como dependencia en useEffect. Entonces el código final se ve así:

 useEffect(() => { try { setLoading(true) const id = props.match.params.id loadProfile(id) } catch (e) { setLoading(false) history.push("/aufgabenliste") } }, [props]);
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!