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

165
Views
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 answers
Answer question

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 Report
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!