Safwen Hafsawy
Safwen Hafsawy

Reputation: 59

Redirect page in react class component

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

Answers (1)

Yousaf
Yousaf

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

export default withRouter(MyComponent);

Upvotes: 1

Related Questions