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

251
Views
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 answers
Answer question

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 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!