How to emulate window.location with react-router and ES6 classes

After wasting time with react router, I finally switch to basic javascript.

  1. Create a component for your redirect:

    Route path=”*” component={NotFound}

  2. In the component use window.location to redirect:

     componentDidMount() {
          if (typeof window !== 'undefined') {
               window.location.href = "http://foo.com/error.php";
          }
     }
    

Leave a Comment