Search code examples
javascriptreactjsreact-routerkoa2

React-router and server sided rendering


I would like to render server sided with react-router and Koa. However I only got it to work if I included the full node build. This is duo to my components requiring sass compiling, image handling and the like.

It would be great if my front end application is pre-compiled and routes and their relative pages rendered to string are obtained from there.

Right now I import routes from a routes.js file which exports the following and with it the uncompiled components:

export default (
    <Route path="/" component={Shell}>
        <IndexRoute component={Home} />
        <Route path="sub">
            <Route path="zero" component={SubZero} />
        </Route>
        <Route path="finish" component={Him} />
    </Route>
)

Solution

  • I will dig through https://github.com/RickWong/react-isomorphic-starterkit

    It will probably shine light upon my question.

    Edit: Infact it does. Compiling the server.js file which imports routes with webpack will compile into an server file which has all magic (image minifying, sass compiling etc) done.