title: Prevent navigation until React form is validated
body: <p>I'm trying to implement a validation functionality in React wherein the user will fill in a form, and then the user can navigate to other tabs of the application.</p>
  <p>What i want to do is disabling the navigation until certain parts of the form has been filled, if the user attempts to change the tabs without filling said fields, a message will appear directly on the page to alert the user that the fields are required.</p>
  <p>My current approach is to capture the event prior to the page switch, check for the form's validity, and then decide whether or not the user can navigate based on said.</p>
  <p>The problem is I have no idea which event to capture or how to prevent user's navigation, can someone help me?</p>
  <p>EDIT:
  Here's what i've tried so far:</p>
  <pre><code>componentWillUnmount() {
      this.handleValidation();
    }
  handleValidation = () =&gt; {
      if (this.invalidForm()) {
        this.setState({ showValidation: true });
        this.preventNavigation();
      }
    };
  preventNavigation = () =&gt; {
      window.location.reload();
    }
  
  render()
  return (
              ///Form information...
             {this.state.showValidation &amp;&amp; (
              &lt;div&gt;
                You must provide all required information
              &lt;/div&gt;
            )}
  )
  </code></pre>
  <p>I've thought that by using location.reload in componentWillUnmount(), the page would be reloaded before the navigation (hence, making the user stay in the old page), but what really happens is that it navigates to the other tab, then proceeds to reload there.</p>