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

225
Vistas
In React, replacing URL with an identical value causes infinite loop
      if (new_path !== window.location.pathname + window.location.search) {
        history.replace({
          pathname: new_path,
          search: "",
        });
      }

EDITED:

new_path is just a string. Without the if statement, the above code will cause infinite loop.

Is that expected behavior?

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

0

It will only cause an infinite loop if

new_path is different than window.location.pathname + window.location.search.

If you want to check its values, try to preserve logs on chrome developer tools and then start your app. That way you can see why it is generating an infinite loop.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If new_path is a state in your app it should be inside {}

pathname: {new_path}
about 4 years ago · Juan Pablo Isaza Denunciar

0

The "if" condition is the wrong one.

if (new_path !== window.location.pathname + window.location.search) {}

This will be true always and history.replace will run again.

so the solution is

if (new_path[<your key>] !== window.location[<your key>]) {}

If you meant to be the new_path is a string, you need to check what is the new_path value

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