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

317
Views
React - How to hide register/login in navbar once a user has logged in?

I want to be able to hide the links to register and log in once a user has logged in. I'm using react.

Here are the links in my nav:

<Navbar>
 <Nav.Item>
            <Nav.Link href="/Register">Register</Nav.Link>
          </Nav.Item>
          <Nav.Item>
            <Nav.Link href="/Login">Login</Nav.Link>
          </Nav.Item>
</Navbar>

I'm using local storage for the login:

localStorage.setItem("userID", user);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can get the item with localStorage.getItem('userID') and use it to hide the links

<Navbar>
          {!localStorage.getItem('userID') && (
            <Nav.Item>
          
              <Nav.Link href="/Register">Register</Nav.Link>
            </Nav.Item>
            <Nav.Item>
              <Nav.Link href="/Login">Login</Nav.Link>
            </Nav.Item>
          )}
</Navbar>

this way the links will only be displayed if localStorage.getItem('userID') is undefined or has any falsy value

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!