Reputation: 59
how can i redirect the page in react's class component after performing submiting a form (like create a post, login etc...) ? is there an equivalent to useHistory hook for class based component ?
Upvotes: 0
Views: 56
Reputation: 29354
You can use history prop.
this.props.history.push('/path to page');
If history prop is not available in your component, wrap your component with withRouter
history
withRouter
export default withRouter(MyComponent);
Upvotes: 1