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

156
Views
React router v6 - Route render - navigate if signed in

I'm stumped on how to render the signIn component if currentUser is not detected. I am not getting any errors, only that it is rendering an empty component due to the value "currentUser = null".

<Routes>
   <Route exact path='/' element={<HomePage />} />
   <Route exact path='/shop' element={<ShopPage />} />
   <Route exact path='/signIn' 
          render={() => 
            currentUser ?
              <Navigate to='/' /> 
              :
              <SignIn />
          }
    />
   <Route exact path='/register' element={<Register />} />
</Routes>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming that currentUser is defined inside the component that is rendering the routes, you would wanna do it this way instead:

// routes
<Routes>
  <Route exact path='/' element={<HomePage />} />
  <Route exact path='/shop' element={<ShopPage />} />
  <Route exact path='/signIn' element ={ <SignIn currentUser={currentUser}/>}/>
  <Route exact path='/register' element={<Register />} />
</Routes>

// SignIn
export function SignIn({currentUser}){
  if(currentUser){
      return <Navigate to ="/"/>
  }
  return <div>Hello</div>
}

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!