Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda