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

120
Visualizações
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
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