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

147
Vistas
How to remove trailing forward slash from History before pushing?

I understand that due to some React Router logic, a forward slash is appended onto the url on refresh.

Some context, I am displaying a page that renders some company info based on the company at the end of the url. Since I split and extract the companies via "/", my page loads perfectly with or without the last slash.

The problem now is that if I ever refresh the page, and it appends a trailing forward slash, when I change the company, it messes up.

Example:

Original URL: https://www.payranked.com/companies/bytedance

Refreshed URL: https://www.payranked.com/companies/bytedance/

If I were to navigate to another page:

Without trailing slash: https://www.payranked.com/companies/accenture

With trailing slash: https://www.payranked.com/companies/bytedance/accenture

As seen, if there is a page refresh, then my URL gets messed up.

Here is my current code:

const history = useHistory();

// Some code...

// Used to extract company string, then uses MySQL call to display info
const location = useLocation();
const companyURL = location.pathname.split('/')[2];

// companyDropdown is the key returned from selecting a company in the dropdown.
let companyDropdownURL = CompanyNameToURL[companyDropdown]; 

history.push({
  pathname:  `${companyDropdownURL}`,
    state: {
      response: '' 
    } 
});

companyDropdownURL is essentially a value from a map CompanyNameToURL. I.e. if I was searching JPMorgan Chase (companyDropdown), companyDropdownURL would be jpmorgan-chase, which is reflected in the URL.

How would I feasible approach this issue, either by editing the history somehow or by another method. Thanks!

Edit: Added more information

about 4 years ago · Juan Pablo Isaza
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