-1

I'm working with React Router V5.

I have implemented my application routes.

  • HomeComponent for all users
  • LoginComponent only for not logged in users.

My issue is when i'm logged in and i go into /login then i stuck on blank page. I want achieve redirection into home component. Login component should be only available

Could you tell me what is wrong with my routes?

export const AppRoutes = () => {
  const { currentUser } = useAuth();
  return (
    <Switch>
      {!currentUser.isLoggedIn && <Route exact path='/login' component={Login} />}
      <Layout>
        <Switch>
          <Route exact path='/' component={Home} />
          <Redirect to='/' />
        </Switch>
      </Layout>
    </Switch>
I3art0sh
  • 23
  • 1
  • 5
  • Might help https://stackoverflow.com/questions/66289122/how-to-create-a-protected-route. – Youssouf Oumar May 26 '22 at 19:20
  • Your previous question was closed as a duplicate. Please don't repost the same identical question. Edit the existing post to improve the question and explain why it might not be a duplicate. Is there some specific aspect of the duplicate question you've tried and still have some issue? – Drew Reese May 26 '22 at 19:29

1 Answers1

0

Use Redirect

{!currentUser.isLoggedIn ? <Route exact path='/login' component={Login} /> : <Redirect to="/" />}
charchit
  • 1,492
  • 2
  • 6
  • 17