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

167
Visualizações
React router how to make routing for overlay modal

I want to create routing for overlay modal with parent page in background. Just like in instagram.com , When you click create icon it takes u to "/create/select" while the parent page is still in background.

I tried to implement this in my own page, but it didn't seem to work, it renders the whole new page instead of parent page.

function Routes(){
    return(
        <Router>
      
            <Switch>
                <Route path = "/login" component = {LoginPage} />
                <Route path = "/signup/name" component = {NamePage} />
                <Route path = "/signup" component = { SignupPage } />
                <MainContainer> 
                    <Route path = "/" exact component = {HomePage} />
                    <Route path = "/explore" component = {Overlay} />
                </MainContainer>
            </Switch>
            <Route path = "/create" children = {<Overlay />}/>
        </Router>
    )
}
function MainContainer(props: any){
    return(
        <userContext.Provider value = {currentUser}>
            <div id = "main-container">
                <NavComponent />
                <div className = "main-container-right">
                    <HeaderComponent />
                    <main id = "container">
                        {props.children}
                    </main>
                </div>
            </div>
        </userContext.Provider>
        
    )
   
}

It works when I remove exact from the "/" route, but I want the router switch page in "/explore". Is there anything I am doing wrong here?

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

0

If it's overlaying the background (parent) component, do you really need to change the route path? If so, my answer may be incomplete.

For overlaying, just put the overlayed component inside the parent's render function. However, you can use the parent's state to decide whether the child/overlay gets rendered.

For example:

render() {
    return (
        {this.state.overlay === true && <Overlay />}
    )
}

This uses a property in the state called overlay - which should likely be false by default. Then just use a function in the parent component to toggle this on/off. You can pass this toggle in to the overlay function in order to close out the overlay.

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