I am trying to take user to welcome page after logging in. but react doesnot take it to the welcome page, instead, automatically goes back to the login page.
handleLogins(event) {
fetch(`http://localhost:5000/user/get?email=abc@gmail.com&password=abc`)
.then((response) => {
return response.json()
}).then((response) => {
this.setState({
User_FirstNameNew: response.data[0].User_FirstName,
User_LastNameNew : response.data[0].User_LastName,
toWelcome: true
})
ReactDOM.render((
<Router>
<Welcome/>
</Router>
), document.getElementById('root'))
});
}
How are you redirecting from your login page to welcome?
Make sure you're doing something this.props.location.push('/welcome');
Also, if you're checking isUserLoggedIn
on welcome page and passing the value as a prop, you have to update the prop first and redirect later. Share some reference code regarding this logic in from your source.
Hi I figured out that I used form tag and button with type as submit. This caused the redirection to somehow come back to the same page. I changed the type of the button and it worked well. Can someone explain this behaviour?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.