Last active
November 9, 2022 05:21
-
-
Save elitan/5e4cab413dc201e0598ee05287ee4338 to your computer and use it in GitHub Desktop.
React Router V4 Redirect after form submission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { withRouter } from 'react-router-dom'; // <--- import `withRouter`. We will use this in the bottom of our file. | |
class ContactForm extends Component { | |
submitForm (e) { | |
e.preventDefault() | |
this.props.history.push('/thank-you'); // <--- The page you want to redirect your user to. | |
} | |
render() { | |
return ( | |
<div> | |
<form onSubmit={this.submitForm.bind(this)}> | |
<button type="submit">Submit</button> | |
</form> | |
</div> | |
); | |
} | |
} | |
export default withRouter(ContactForm); // <--- make sure to wrap your component with `withRouter()` |
It works! I love you!
❤️
Thanks a lot!
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works! I love you!