Skip to content
This repository was archived by the owner on Sep 11, 2018. It is now read-only.

Commit 29074ac

Browse files
committed
tmp
1 parent 8469de0 commit 29074ac

File tree

10 files changed

+6192
-43
lines changed

10 files changed

+6192
-43
lines changed

bin/compile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const compile = () => {
1616
}
1717
debug('Copying static assets to dist folder.')
1818
fs.copySync(paths.client('static'), paths.dist())
19+
// fs.writeFile(paths.dist('manifest.json'), JSON.stringify(stats))
1920
})
2021
.then(() => {
2122
debug('Compilation completed successfully.')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"react": "^15.0.0",
100100
"react-dom": "^15.0.0",
101101
"react-redux": "^4.4.5",
102-
"react-router": "^2.8.0",
102+
"react-router": "next",
103103
"redux": "^3.6.0",
104104
"redux-thunk": "^2.0.0",
105105
"rimraf": "^2.5.4",

src/containers/AppContainer.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import React, { Component, PropTypes } from 'react'
2-
import { Router, RouterContext } from 'react-router'
2+
import { Match, BrowserRouter, ServerRouter } from 'react-router'
33
import { Provider } from 'react-redux'
44

5+
const MatchWithSubRoutes = (route) => (
6+
<Match {...route} render={(props) => (
7+
// pass the sub-routes down to keep nesting
8+
<route.component {...props} routes={route.routes} />
9+
)} />
10+
)
11+
512
class AppContainer extends Component {
613
static propTypes = {
714
routes : PropTypes.object.isRequired,
@@ -17,10 +24,17 @@ class AppContainer extends Component {
1724

1825
let router
1926
if (!window.__IS_SSR) {
20-
let browserHistory = require('react-router').browserHistory
21-
router = <Router history={browserHistory} children={routes} />
27+
router = <BrowserRouter>
28+
{routes.map((route, i) => (
29+
<MatchWithSubRoutes key={i} {...route} />
30+
))}
31+
</BrowserRouter>
2232
} else {
23-
router = <RouterContext children={routes} />
33+
router = <ServerRouter>
34+
{routes.map((route, i) => (
35+
<MatchWithSubRoutes key={i} {...route} />
36+
))}
37+
</ServerRouter>
2438
}
2539

2640
return (

src/main.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'
33
import ReactDomServer from 'react-dom/server'
44
import 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'
77
import { 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+
1825
let render
1926

2027
if (!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
}

src/routes/Counter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { injectReducer } from '../../store/reducers'
22

33
export default (store) => ({
4-
path : 'counter',
4+
pattern : 'counter',
55
/* Async getComponent is only invoked when route matches */
66
getComponent (nextState, cb) {
77
/* Webpack - use 'require.ensure' to create a split point

src/routes/Home/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import HomeView from './components/HomeView'
22

33
// Sync route definition
44
export default {
5+
pattern: '/',
56
component : HomeView
67
}

src/routes/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
// We only need to import the modules necessary for initial render
2-
import CoreLayout from '../layouts/CoreLayout/CoreLayout'
3-
import Home from './Home'
4-
import CounterRoute from './Counter'
2+
// import CoreLayout from '../layouts/CoreLayout/CoreLayout'
3+
import HomeRoute from './Home'
4+
// import CounterRoute from './Counter'
55

66
/* Note: Instead of using JSX, we recommend using react-router
77
PlainRoute objects to build route definitions. */
88

9-
export const createRoutes = (store) => ({
10-
path : '/',
11-
component : CoreLayout,
12-
indexRoute : Home,
13-
childRoutes : [
14-
CounterRoute(store)
15-
]
16-
})
9+
export const createRoutes = (store) => ([
10+
HomeRoute
11+
// CounterRoute(store)
12+
])
1713

1814
/* Note: childRoutes can be chunked or otherwise loaded programmatically
1915
using getChildRoutes with the following signature:

src/store/createStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { applyMiddleware, compose, createStore } from 'redux'
22
import thunk from 'redux-thunk'
33
import makeRootReducer from './reducers'
4-
import { updateLocation } from './location'
4+
// import { updateLocation } from './location'
55

66
export default (initialState = {}) => {
77
// ======================================================
@@ -35,8 +35,8 @@ export default (initialState = {}) => {
3535

3636
// To unsubscribe, invoke `store.unsubscribeHistory()` anytime
3737
if (!window.__IS_SSR) {
38-
const browserHistory = require('react-router').browserHistory
39-
store.unsubscribeHistory = browserHistory.listen(updateLocation(store))
38+
// const browserHistory = require('react-router').browserHistory
39+
// store.unsubscribeHistory = browserHistory.listen(updateLocation(store))
4040
}
4141

4242
if (module.hot) {

tests/routes/Counter/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('(Route) Counter', () => {
1111
expect(typeof _route).to.equal('object')
1212
})
1313

14-
it('Configuration should contain path `counter`', () => {
15-
expect(_route.path).to.equal('counter')
16-
})
14+
// it('Configuration should contain path `counter`', () => {
15+
// expect(_route.path).to.equal('counter')
16+
// })
1717
})

0 commit comments

Comments
 (0)