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

157
Views
How can I redirect login to current page in react js?

I create a single page application using react. I create protected route but after login, I can access login page after login. If I try to go login route I can access. How can I prevent to this. If I try to access login page It will redirect login to my current page.

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

0

This is assuming you're using react-router, but you essentially want to be able to check if the user is logged in, and if they are then you want to conditionally remove the <Route... definition for login.

example:

export function App() {
return (
  <Routes>
    <Route path="/" element={<DataPipelineEditorView />} />
    {isUserLoggedIn ? null : <Route path="/login" element={<Login />} />}
  </Routes>
}

You'll just need to figure out how to populate the isUserLoggedIn. If you have a react context (or some other means) that holds the state of your user's login session (or maybe a local storage cookie) you can check it in the component and render the Routes accordingly.

If you're not using react router then share your code and we can go from there!

about 4 years ago · Juan Pablo Isaza Report

0

you can use

  Router,
  Switch,
  Route,
  Link

for it.

here I put a example for route example, hope it will help you.

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!