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

161
Views
How to prevent react router 5 to render DashboardLayout component below specific route?

I am trying to create a route that works as follows:

 <Route path='/home' exact component={Home}/>
{loggedin &&
<DashboardLayout>
<Route path='/settings' exact component={Settings} />
<Route path='/edit' exact component={AdMaker} />
</DashboardLayout>
}

If I am logged in, the DashboardLayout is rendering which I dont want if the route is /home. What should i do? [Please recommend methods other than switch]

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are many different way to do it, one of them is checking the pathname

let location = useLocation();

let checkIsHome = () => {
    return location.pathname?.includes('home')
}
 
<Route path='/home' exact component={Home}/>
{loggedin && !checkIsHome() &&
  <DashboardLayout>
    <Route path='/settings' exact component={Settings} />
    <Route path='/edit' exact component={AdMaker} />
  </DashboardLayout>
}
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!