title: React build for static server gives 404 error
body: <p>I have a <code>React</code> app which runs fine locally but when I try to build it on the static <code>Node</code> server <code>serve</code> (<a href="https://www.npmjs.com/package/serve" rel="nofollow noreferrer">npm serve</a>) using</p>
  
  <pre><code>serve -s build
  </code></pre>
  
  <p>the server returns a <code>404 The requested path could not be found</code> page. My understanding is the issue has to do with the fact I am using <code>BrowserRouter</code> in the application. I put a <code>.htaccess</code> file in the root directory with the following code but it did not solve the issue.</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule . /index.html [L]
  
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>One suggestion I saw for a <code>Node</code> environment follows but I don't understand where to put the code.</p>
  
  <pre><code>app.get('*', function (req, res) {
    res.send('index_path')
  })
  </code></pre>
  
  <p>My index.js file is as follows.</p>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  import './index.css';
  import { Route, Switch, BrowserRouter as Router } from 'react-router-dom';
  import App from './App';
  import Service from './javascript/Service';
  import { PageNotFound } from './PageNotFound';
  import * as serviceWorker from './serviceWorker';
  
  const routing = (
      &lt;Router&gt;
          &lt;Switch&gt;
              &lt;Route exact path="/" component={App} /&gt;
              &lt;Route path="/Service/:serviceName" component={Service} /&gt;
              &lt;Route component={PageNotFound} /&gt;
          &lt;/Switch&gt;
      &lt;/Router&gt;    
  );
  
  ReactDOM.render(routing, document.getElementById('root'));
  
  serviceWorker.unregister();
  </code></pre>