class Login extends Component {
async handle_login(e) {
e.preventDefault();
this.props.history.push('/home')
}
render() {
return (
<input type='submit' value='Log in' onSubmit={(e)=>this.handle_login(e)}></input>
<input type='submit'value='Sign up' onSubmit={(e)=>this.handle_signup(e)}></input>
);
}
}
export default withRouter(Login)
class App extends Component {
// app.js
render() {
return (
<Router>
<div className='App' style={{marginTop:'0px'}}>
<div className='container'>
<Header></Header>
<Route exact style={{marginTop:'0px'}} path='/' render={(props)=>(
<div style={{display:'flex',justifyContent:'center'}}>
{/* add a background in this div */}
<Link to='/login' style={{color:'#000000', fontSize:'large',paddingRight:'10px' }}> Login </Link>
<Link to='/' style={{color:'#000000', fontSize:'large' }}> Index </Link>
</div>
)}></Route>
<Route exact path='/home' component={Home}></Route>
<Route exact path='/login' component={Login}></Route>
</div>
</div>
</Router>
);
}}
export default App;
I am trying to redirect the 'login' component to the '/home' using withRouter using the aforementioned code, but running the code does nothing, neither does it throw any error.I have attached the codes of both the home and the login components.
console.log(this.props.history)and let us know if you got anythingconsole.log(this.props.history)in the "handle_login" function, but nothing logged on the console.@BARNOWLconsole.log(this.props)console.log(this.props)in the "handle_login" function, but nothing got rendered on the console.@BARNOWLconsole.log(this.props)in therendermethod, and the props do contain thehistoryattribute.@BARNOWL