2

In the below code if add Link tag from the react router dom, it routes the next page without validating the form. I'm using redux form and default required keyword in the tag to validate the form. After validation it should route the component to say "/" homepage.

<button type="submit" className="btn btn-primary">
  <Link>Create Account</Link>
</button>
Soroush Chehresa
  • 5,490
  • 1
  • 14
  • 29
Gowtham Koushik
  • 274
  • 1
  • 6
  • 14

1 Answers1

3

You should use history.push('/') to change route after validation like this:

<button 
  type="submit" 
  className="btn btn-primary" 
  onClick={() => history.push('/')}
>
  Create Account
</button>

You can learn the history usage from this answer: How to push to History in React Router v4?

Soroush Chehresa
  • 5,490
  • 1
  • 14
  • 29