@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'
33import ReactDomServer from 'react-dom/server'
44import createStore from './store/createStore'
55// import AppContainer from './containers/AppContainer'
6- import { match , Router , RouterContext } from 'react-router'
6+ import { Match , BrowserRouter , ServerRouter , createServerRenderContext } from 'react-router'
77import { Provider } from 'react-redux'
88
99// ========================================================
@@ -15,17 +15,25 @@ const store = createStore(initialState)
1515// ========================================================
1616// Render Setup
1717// ========================================================
18+ const MatchWithSubRoutes = ( route ) => (
19+ < Match { ...route } render = { ( props ) => (
20+ // pass the sub-routes down to keep nesting
21+ < route . component { ...props } routes = { route . routes } />
22+ ) } />
23+ )
24+
1825let render
1926
2027if ( ! window . __IS_SSR ) {
2128 const MOUNT_NODE = document . getElementById ( 'root' )
2229 render = ( ) => {
2330 const routes = require ( './routes/index' ) . default ( store )
24- const browserHistory = require ( 'react-router' ) . browserHistory
2531 ReactDOM . render (
2632 < Provider store = { store } >
2733 < div style = { { height : '100%' } } >
28- < Router history = { browserHistory } children = { routes } />
34+ < BrowserRouter >
35+ < MatchWithSubRoutes key = { 0 } { ...routes [ 0 ] } />
36+ </ BrowserRouter >
2937 </ div >
3038 </ Provider > ,
3139 MOUNT_NODE
@@ -73,25 +81,33 @@ if (!window.__IS_SSR) {
7381} else {
7482 render = ( ) => {
7583 const routes = require ( './routes/index' ) . default ( store )
76- let html = ''
77- match ( { routes, location : '/' } , ( error , redirectionLocation , renderProps ) => {
78- if ( error ) {
84+ let requestUrl = window [ 'requestUrl' ] || '/'
7985
80- } else if ( redirectionLocation ) {
86+ const context = createServerRenderContext ( )
87+ let html = ReactDomServer . renderToString (
88+ < ServerRouter context = { context } location = { requestUrl } >
89+ < MatchWithSubRoutes key = { 0 } { ...routes [ 0 ] } />
90+ </ ServerRouter >
91+ )
8192
82- } else if ( renderProps ) {
83- html = ReactDomServer . renderToString (
84- < Provider store = { store } >
85- < div style = { { height : '100%' } } >
86- < RouterContext { ...renderProps } />
87- </ div >
88- </ Provider >
89- )
90- console . log ( )
91- } else {
92- // 404
93- }
94- } )
93+ // match({ routes, location: '/' }, (error, redirectionLocation, renderProps) => {
94+ // if (error) {
95+ //
96+ // } else if (redirectionLocation) {
97+ //
98+ // } else if (renderProps) {
99+ // html = ReactDomServer.renderToString(
100+ // <Provider store={store}>
101+ // <div style={{ height: '100%' }}>
102+ // <RouterContext {...renderProps} />
103+ // </div>
104+ // </Provider>
105+ // )
106+ // console.log()
107+ // } else {
108+ // // 404
109+ // }
110+ // })
95111
96112 return html
97113 }
0 commit comments