Skip to content

Commit a8062d5

Browse files
committed
Update for React Router v1.0.0-rc1
1 parent faabae6 commit a8062d5

5 files changed

Lines changed: 22 additions & 18 deletions

File tree

docs/build.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint no-console: 0 */
22

33
import fsp from 'fs-promise';
4+
import createLocation from 'history/lib/createLocation';
45
import path from 'path';
56
import React from 'react';
67
import ReactDOMServer from 'react-dom/server';
7-
import Router from 'react-router';
8-
import Location from 'react-router/lib/Location';
8+
import {match, RoutingContext} from 'react-router';
99

1010
import Root from './src/Root';
1111
import routes from './src/Routes';
@@ -32,10 +32,11 @@ const readmeDest = path.join(docsBuilt, 'README.md');
3232
function generateHTML(fileName) {
3333
return new Promise( resolve => {
3434
const urlSlug = fileName === 'index.html' ? '/' : `/${fileName}`;
35+
const location = createLocation(urlSlug);
3536

36-
Router.run(routes, new Location(urlSlug), (error, initialState) => {
37+
match({routes, location}, (error, redirectLocation, renderProps) => {
3738
let html = ReactDOMServer.renderToString(
38-
<Router {...initialState} />
39+
<RoutingContext {...renderProps} />
3940
);
4041
html = '<!doctype html>' + html;
4142
let write = fsp.writeFile(path.join(docsBuilt, fileName), html);

docs/client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import CodeMirror from 'codemirror';
22
import 'codemirror/addon/runmode/runmode';
33
import 'codemirror/mode/htmlmixed/htmlmixed';
44
import 'codemirror/mode/javascript/javascript';
5+
import createBrowserHistory from 'history/lib/createBrowserHistory';
56
import React from 'react';
67
import ReactDOM from 'react-dom';
78
import {Router} from 'react-router';
8-
import {history} from 'react-router/lib/BrowserHistory';
99

1010
import Root from './src/Root';
1111
import routes from './src/Routes';
@@ -30,6 +30,8 @@ global.CodeMirror = CodeMirror;
3030
Root.assetBaseUrl = window.ASSET_BASE_URL;
3131
Root.propData = window.PROP_DATA;
3232

33+
const history = createBrowserHistory();
34+
3335
ReactDOM.render(
3436
<Router history={history} children={routes} />,
3537
document

docs/server.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import 'colors';
44
import express from 'express';
5+
import createLocation from 'history/lib/createLocation';
56
import httpProxy from 'http-proxy';
67
import ip from 'ip';
78
import path from 'path';
89
import React from 'react';
910
import ReactDOMServer from 'react-dom/server';
10-
import Router from 'react-router';
11-
import Location from 'react-router/lib/Location';
11+
import {match, RoutingContext} from 'react-router';
1212

1313
import Root from './src/Root';
1414
import routes from './src/Routes';
@@ -46,9 +46,10 @@ if (development) {
4646
res.header('Access-Control-Allow-Origin', target);
4747
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
4848

49-
Router.run(routes, new Location(req.url), (error, initialState) => {
49+
const location = createLocation(req.url);
50+
match({routes, location}, (error, redirectLocation, renderProps) => {
5051
const html = ReactDOMServer.renderToString(
51-
<Router {...initialState} />
52+
<RoutingContext {...renderProps} />
5253
);
5354
res.send('<!doctype html>' + html);
5455
});

docs/src/Routes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {Route} from 'react-router';
2+
import {IndexRoute, Route} from 'react-router';
33

44
import ComponentsPage from './ComponentsPage';
55
import GettingStartedPage from './GettingStartedPage';
@@ -10,12 +10,12 @@ import Root from './Root';
1010
import SupportPage from './SupportPage';
1111

1212
export default (
13-
<Route component={Root}>
14-
<Route path="/" component={HomePage} />
15-
<Route path="/introduction.html" component={IntroductionPage} />
16-
<Route path="/getting-started.html" component={GettingStartedPage} />
17-
<Route path="/components.html" component={ComponentsPage} />
18-
<Route path="/support.html" component={SupportPage} />
13+
<Route path="/" component={Root}>
14+
<IndexRoute component={HomePage} />
15+
<Route path="introduction.html" component={IntroductionPage} />
16+
<Route path="getting-started.html" component={GettingStartedPage} />
17+
<Route path="components.html" component={ComponentsPage} />
18+
<Route path="support.html" component={SupportPage} />
1919

2020
<Route path="*" component={NotFoundPage} />
2121
</Route>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"docs": "babel-node docs/dev-run",
1919
"docs-prod": "npm run docs-build && NODE_ENV=production babel-node docs/server.js",
2020
"docs-prod-unoptimized": "npm run docs-build -- --dev && NODE_ENV=production babel-node docs/server.js",
21-
2221
"minor": "node ./tools/release minor",
2322
"patch": "node ./tools/release patch"
2423
},
@@ -70,6 +69,7 @@
7069
"fs-extra": "^0.23.0",
7170
"fs-promise": "^0.3.1",
7271
"glob": "^5.0.14",
72+
"history": "^1.9.0",
7373
"http-proxy": "^1.11.1",
7474
"ip": "^0.3.3",
7575
"isparta-loader": "^0.2.0",
@@ -100,7 +100,7 @@
100100
"react-component-metadata": "^1.3.0",
101101
"react-dom": "^0.14.0-rc1",
102102
"react-hot-loader": "^1.2.8",
103-
"react-router": "^1.0.0-beta3",
103+
"react-router": "^1.0.0-rc1",
104104
"rimraf": "^2.4.2",
105105
"semver": "^5.0.1",
106106
"sinon": "^1.15.4",

0 commit comments

Comments
 (0)