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

119
Views
React Router Path Parameter Disappears After Page Reload

I am encountering a pretty weird problem with react-routerv6. My Routes are like this

 <Routes>
        <Route path="*" element={<NotFound />} />
        <Route path="/" element={<Landing />} />
        <Route
          path="/project/:id"
          element={
            <PrivateRoute>
              <SpecificProjectPage />
            </PrivateRoute>
          }
        />
      </Routes>

Now the path parameters are working fine until I reload the page. The following image recreates the error.

Error Recreation

The path parameter disappears on reload and the route is matched to the last route.

What I have done till now to fix

I tried installing the latest react-router version. Tried uninstalling react-router and react-router-dom and reinstalling only react-router-dom.

Edit - 1

Here Private Route is Basically a utility component that redirects to the main page if the user is not authorized.

Here is its code

const PrivateRoute = ({ children }) => {
  let { user } = useAuth();
  return user ? children : <Navigate to={'/'} />;
};

And Not Found Page is a component rendered on wild card routes as there are no matches for /project in Routes

Here is the code for <NotFound /> component

export default function NotFound() {
  return (
  <Flex
   direction="column">
    <Heading
      >
        404
      </Heading>
      <Text fontSize="18px" mt={3} mb={2}>
        Page Not Found
      </Text>
      <Text color={'gray.500'} mb={6}>
        The page you're looking for does not seem to exist
      </Text>

      <Button
        colorScheme={'cyan'}
        variant="solid"
        onClick={() => {
            window.location.href = '/';
        }}
      >
        Go to Home
      </Button>
  </Flex>
  );
}
about 4 years ago · Santiago Trujillo
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!