qimingweng / static-render-webpack-plugin

Generates a series of static routes for a website, given an array of routes
http://www.qimingweng.com/writing/webpack-static-render
MIT License
39 stars 2 forks source link

Using react-router 1.0 #3

Closed oojacoboo closed 8 years ago

oojacoboo commented 8 years ago

Any docs on how to implement with the new API changes on react-router 2.x?

qimingweng commented 8 years ago

The main export is just a function which takes any callback.

import { match } from 'react-router';

module.exports = (path, props, callback) => {
  html = '';
  match({ routes, location: path, basename: '/' }, (err, redirectLocation, renderProps) => {
    html = ReactDOMServer.renderToString(
      <RouterContext {...renderProps}>{routes}</RouterContext>
    );
  });
  callback(html);
};
oojacoboo commented 8 years ago

Thanks yea, I actually came up with something quite similar to this.