0 votes
in ReactJS by

How to perform automatic redirect after login?

1 Answer

0 votes
by
  1. The react-router package provides <Redirect> component in React Router. Rendering a <Redirect> will navigate to a new location. Like server-side redirects, the new location will override the current location in the history stack.

    import React, { Component } from 'react'
    import { Redirect } from 'react-router'
    
    export default class LoginComponent extends Component {
      render() {
        if (this.state.isLoggedIn === true) {
          return <Redirect to="/your/redirect/page" />
        } else {
          return <div>{'Login Please'}</div>
        }
      }
    }

Related questions

0 votes
asked Jan 9, 2020 in VueJS by GeorgeBell
0 votes
0 votes
asked May 14, 2019 in Other by Robindeniel
...