Server-side rendering with react-router is not working
<p>I'm using express, and I want to do some basic routing server-side.  At the moment I'm just trying to set up the router to do <em>anything</em>.  Right now it always returns a 404.</p>

<p>I believe I've followed the directions listed on <a href="https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md" rel="nofollow">https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md</a>.</p>

<p>It's about as basic as you can get: an express server that routes every request to be handled by the code from the link listed above, and a ReactRouter that routes everything to the AppTemplate component.</p>

<p>It's definitely getting to the callback in routes.js, because it returns 'Not found' for every request.</p>

<p>I doubt it matters, but I'm running it in IIS via iisnode.  I've been having troubles debugging, which is one of the reasons I'm switching from express-react-views to routing via the <code>&lt;Router&gt;</code>.</p>

<p>Let me know what other information i can get you.</p>

<h3>File structure:</h3>

<pre><code>server/
-- server.js // just calls babel-register and express-app.js
-- express-app.js
-- router.js

server/views/
-- app-template.js
-- routes.js
</code></pre>

<h3>server/express-app.js</h3>

<pre><code>import Express from 'express';
import BodyParser from 'body-parser';
import CookieParser from 'cookie-parser';

let app = new Express();
export default app;

app.enable('trust proxy');

app.use('/public', Express.static('../dist'));

app.use(BodyParser.urlencoded({ extended: true }));
app.use(BodyParser.json());
app.use(CookieParser());

// some rest API code here, currently commented out

app.set('tokenSecret', process.env.tokenSecret);

require('./router');
</code></pre>

<h3>server/router.js</h3>

<pre><code>// copied right from https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md.
import { renderToString } from 'react-dom/server';
import { match, RouterContext} from 'react-router';

import app from './express-app';
import Routes from './views/routes';

app.get('/*', (req, res) =&gt; {
    match({ Routes, location: req.originalUrl }, (error, redirectLocation, renderProps) =&gt; {
        if (error) {
            res.status(500).send(error.message);
        } else if (redirectLocation) {
            res.redirect(302, redirectLocation.pathname + redirectLocation.search);
        } else if (renderProps) {
            res.status(200).send(renderToString(&lt;RouterContext {...renderProps} /&gt;));
        } else {
            res.status(404).send('Not found');
        }
    });
});
</code></pre>

<h3>server/views/routes.js</h3>

<pre><code>import React from 'react';
import {Router, Route, IndexRoute} from 'react-router';

import AppTemplate from './app-template';

export default (
    &lt;Router&gt;
        &lt;Route path='/' component={AppTemplate}&gt;
        &lt;/Route&gt;
    &lt;/Router&gt;
);
</code></pre>

<h3>server/views/app-template.js</h3>

<pre><code>import React from 'react';

export default class AppTemplate extends React.Component {
    constructor() {
        super();
    }

    render() {
        return (
            &lt;html&gt;
                &lt;head&gt;
                &lt;/head&gt;
                &lt;body&gt;
                    &lt;div id='app' /&gt;
                &lt;/body&gt;
            &lt;/html&gt;
        );
    }
};
</code></pre>