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

1.1K
Visualizações
React-router-dom - No routes matching location '/' when Route has param

I'm trying to figure out why passing a param using React-router-dom's Link and Route is not working correctly. My routes are configured this way:

App.tsx

  <Routes>
    <Route path="/:id" element={<Home />} />
    <Route path="/search" element={<Search />} />
  </Routes>

Home renders data using a default initial ID, And I am using Link inside the Search component to send an id param to render data in Home using this different id, this way:

Search.tsx

<Link to={`../${idParam}`}>
  <li>
    Some Link
  </li>
</Link>

What I expect: when the URL points to '/', the default Home component should be rendered. When a param is added Home should receive this param and be rendered using the id sent.

However, currently Home will only be rendered when an id is provided as a param (for example: '/1234'). When navigating to '/', React responds with 'No routes matched location "/"'

Appreciate any help clarifying what's wrong with my set-up, thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Now route matches exact path by default. Uptill v5 we could declare a parameter optional by using a question mark symbol(?). But unfortunately its no longer available in v6. Ref - issues Now instead of optional parameter, you can declare children routes under a parent route. Use the code below in App.tsx

<Routes>
  <Route path="/">
    <Route path=":id" element={<Home />} />
    <Route path="" element={<Home />} />
  </Route>
  <Route path="/search" element={<Search />} />
</Routes>

Also change your code in Search.tsx to

<Link to={`/${idParam}`}>
  <li>
    Some Link
  </li>
</Link>
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