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

141
Visualizações
How do I configure a React router to load two components on top of each other (Overlay)?

I am trying to figure out how to configure my React router to load two overlaying components. I have a route /user/testUser/item/1. If item:id is in the url, an overlay component opens. However, I want the underlying component /user/testUser/ to load as well. When I close my overlay, that is, when I switch from /user/testUser/item/1 to /user/testUser/, the underlying user component is loaded initially. If the /user/testUser/item/1 overlay is open, the underlying user component is not loaded.

<Switch>
                  <PrivateRoute
                    exact
                    path="/user/:id*"
                    component={ProfileView}
                  />

                  <PrivateRoute
                    exact
                    path="*/item/:id"
                    component={ShowItem}
                  />
</Switch>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can not render two routes at a time. You can manage it via optional params and render that component on a particular route.

Example :

<Switch>
  <PrivateRoute
    exact
    path="/user/testUser/item/:id?"
    component={ProfileView}
  />
</Switch>

const ProfileView = () => {
 const { id } = useParams();

 return (
  <>
     {id && <ShowItem />}
     ...
     ...
     <OtherComponent />
  </>

 )
};

You can check conditionally id and based on that render the other components you want.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can't really do it using routes, Switch selects only one Route's component to be rendered. You could probably experiment with having two Switch'es in parallel, but it sounds like the easiest way would be to handle displaying the overlay in the underlaying component.

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