11/* eslint no-console: 0 */
22
3- import React from 'react' ;
3+ import fsp from 'fs-promise' ;
4+ import createLocation from 'history/lib/createLocation' ;
45import path from 'path' ;
5- import Router from 'react-router' ;
6- import routes from './src/Routes' ;
6+ import React from 'react' ;
7+ import ReactDOMServer from 'react-dom/server' ;
8+ import { match , RoutingContext } from 'react-router' ;
9+
710import Root from './src/Root' ;
8- import fsp from 'fs-promise' ;
9- import { copy } from '../tools/fs-utils' ;
10- import { exec } from '../tools/exec' ;
11+ import routes from './src/Routes' ;
12+
1113import metadata from './generate-metadata' ;
1214
15+ import { copy } from '../tools/fs-utils' ;
16+ import { exec } from '../tools/exec' ;
17+
1318const repoRoot = path . resolve ( __dirname , '../' ) ;
1419const docsBuilt = path . join ( repoRoot , 'docs-built' ) ;
1520
@@ -24,12 +29,15 @@ const readmeDest = path.join(docsBuilt, 'README.md');
2429 * @return {Promise } promise
2530 * @internal
2631 */
27- function generateHTML ( fileName , propData ) {
32+ function generateHTML ( fileName ) {
2833 return new Promise ( resolve => {
2934 const urlSlug = fileName === 'index.html' ? '/' : `/${ fileName } ` ;
35+ const location = createLocation ( urlSlug ) ;
3036
31- Router . run ( routes , urlSlug , Handler => {
32- let html = React . renderToString ( React . createElement ( Handler , { propData } ) ) ;
37+ match ( { routes, location} , ( error , redirectLocation , renderProps ) => {
38+ let html = ReactDOMServer . renderToString (
39+ < RoutingContext { ...renderProps } />
40+ ) ;
3341 html = '<!doctype html>' + html ;
3442 let write = fsp . writeFile ( path . join ( docsBuilt , fileName ) , html ) ;
3543 resolve ( write ) ;
@@ -46,7 +54,10 @@ export default function BuildDocs({dev}) {
4654 . then ( ( ) => fsp . mkdir ( docsBuilt ) )
4755 . then ( metadata )
4856 . then ( propData => {
49- let pagesGenerators = Root . getPages ( ) . map ( page => generateHTML ( page , propData ) ) ;
57+ Root . assetBaseUrl = '' ;
58+ Root . propData = propData ;
59+
60+ const pagesGenerators = Root . getPages ( ) . map ( generateHTML ) ;
5061
5162 return Promise . all ( pagesGenerators . concat ( [
5263 exec ( `webpack --config webpack.docs.js --bail ${ devOption } ` ) ,
0 commit comments