I am using react-router
in my application.
On my login page, I need authentication with ajax
and redirect if successful.
Some people like the following code:
class PageLogin extends React.Component { login() { // How to can I redirect to another page if auth success? } render() { return ( <div className="login-page"> <form action=""> <div className="form-group"> <label>Username:</label> <input type="text"/> </div> <div className="form-group"> <label>Password:</label> <input type="text"/> </div> <div> <button onClick={this.login}>Login</button> </div> </form> </div> ) } }
In my login
function, how can I redirect to another page if authentication succeeds?
source share