title: react-router how do I use redirectLocation or the 301 or 302 status
body: <p>We are about to deploy our site in reactjs and we have (re)moved one url but merged it in our main page so from <code>/[product]/menu</code> we merged it to <code>/[product]</code>. Now they said I should respond with 301 for <code>/[product]/menu</code> and redirect it to <code>/[product]</code>, how do I accomplish that and some other pages as well?</p>
  
  <p>How do I setup 301 redirects using react-router? Where do I setup what pages needs to be redirected to what other pages? I have my setup like this right now:</p>
  
  <pre><code>app.get('*', (req, res) =&gt; {
    // routes is our object of React routes defined above
    match({ routes, location: req.url }, (err, redirectLocation, props) =&gt; {
      console.log(redirectLocation);
      if (err) { // something went badly wrong, so 500 with a message
        res.status(500).send(err.message);
  
      // HERE: HOW DO I USE THIS?
      } else if (redirectLocation) { // we matched a ReactRouter redirect, so redirect from the server
        console.log('301/302 yeah!');
        res.redirect(301, redirectLocation.pathname + redirectLocation.search);
  
  ...
  </code></pre>
  
  <p>I use reactjs and express as well.</p>
  
  <p><em>Edit</em> Added route config.</p>
  
  <pre><code>const routes = {
    path: '',
    component: AppComponent,
    childRoutes: [{
      path: '/products',
      component: ProductsComponent,
      name: 'products'
    }, {
      path: '/:slug',
      component: ProductComponent,
      name: 'product'
    }]
  }
  </code></pre>
  
  <p>Just in case. Added answer here:</p>
  
  <pre><code>const routes = {
    path: '',
    component: AppComponent,
    childRoutes: [{
      path: '/products',
      component: ProductsComponent,
      name: 'products'
    }, {
      path: '/:slug',
      component: ProductComponent,
      name: 'product'
    }, { 
      path: '/:product/menu', onEnter(nextState, replace) { replace(`/${nextState.params.product}`) }
    }, {
      path: '/oldlink/:testId', onEnter(nextState, replace) { replace({pathname: `http://newsite.com/oldlink/some/${nextState.params.testId}`}) }
    }]
  }
  </code></pre>