Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda