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

256
Vistas
React-router: useRouteMatch doesn't return current url

I am setting up the routing using react-router and the useRouteMatch hook. I can't load a component because the path is still different than the URL, but I wonder why? Because as you can see the URL in the browser tells me it should match, but then when I log the 'url' value from useRouteMatch() it still is one step behind.

enter image description here

url in browser will be 'http://localhost:3000/compliance/546545/BeleggersProfiel/Profiel', yet when I log the 'url' value from useRouteMatch it will say http://localhost:3000/compliance/546545/BeleggersProfiel, so one step behind.

If I log the path below entered in the Route item, it is '/compliance/:compliance_id/BeleggersProfiel/:substep' so it should match the URL in the browser, but it doesn't. Somebody knows why the url is not up-to-date?

export const routes = [
  {
    path: '/:substep',
    Component: SubSteps,
  },
];
function SubWizardRoutes({ steps, wizardRoutes = routes }) {
  const { push, location } = useHistory();
  const { url, path: basePath } = useRouteMatch();

  // when we entered the app and fetched the steps, proceed to the first step
  if (location.pathname === url && steps.length > 0) {
    push(`${url}/${steps[0].name}`);
  }

  return (
    <Switch>
      {wizardRoutes.map((route) => {
        const { Component, path } = route;
        return (
          <Route
            path={`${basePath}${path}`}
            render={({ ...rest }) => {
              return <Component steps={steps} {...rest} />;
            }}
          />
        );
      })}
    </Switch>
  );
}

export default SubWizardRoutes;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you do not need useRouteMatch to proceed the first step. Please try

const { substep } = useParams()
const isBeforeFirstStep = substep === undefined && steps.length > 0

if (isBeforeFirstStep) {
  const nextURL = `${url}/${steps[0].name}`
  push(nextURL)
}
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