import * as React from 'react' ; import { Provider } from 'react-redux' ; import { renderToString } from 'react-dom/server' ; import { match , RouterContext } from 'react-router' ; import createMemoryHistory from 'history/lib/createMemoryHistory' ; import { createServerRenderer , RenderResult } from 'aspnet-prerendering' ; import routes from './routes' ; import configureStore from './configureStore' ; export default createServerRenderer ( params => { return new Promise < RenderResult > ( ( resolve , reject ) => { const store = configureStore ( ) ; match ( { routes , location : params . location } , ( error , redirectLocation , renderProps ) => { if ( error ) { throw error ; } if ( redirectLocation ) { resolve ( { redirectUrl : redirectLocation . pathname } ) ; return ; } if ( ! renderProps ) { throw new Error ( `The location '${ params . url }' doesn't match any route configured in react-router.` ) ; } const app = ( < Provider store = { store } > < RouterContext { ... renderProps } / > < /Provider>); renderToString ( app ) ; params . domainTasks . then ( ( ) => { resolve ( { html : renderToString ( app ) , globals : { initialReduxState : store . getState ( ) } } ) ; } , reject ) ; } ) ; } ) ; } ) ;