Skip to content

Commit e72812d

Browse files
committed
[added] <Router initialState>
1 parent 85d0b24 commit e72812d

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

modules/Router.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ var Router = createClass({
6666
// Routes may also be given as children (JSX)
6767
children: routes,
6868

69-
// Client-side
69+
// Client
7070
history,
7171

72-
// Server-side
73-
location
72+
// Unit testing, simple server
73+
location,
74+
75+
// Flux, data fetching
76+
initialState: object
7477
},
7578

7679
getDefaultProps() {
@@ -86,7 +89,8 @@ var Router = createClass({
8689
location: null,
8790
routes: null,
8891
params: null,
89-
components: null
92+
components: null,
93+
...this.props.initialState
9094
};
9195
},
9296

@@ -142,13 +146,11 @@ var Router = createClass({
142146
componentWillMount() {
143147
var { routes, children, history, location } = this.props;
144148

145-
invariant(
146-
routes || children,
147-
'<Router>s need routes. Try using <Router routes> or ' +
148-
'passing your routes as nested <Route> children'
149-
);
150-
151-
this.routes = createRoutes(routes || children);
149+
if (routes || children) {
150+
this.routes = createRoutes(routes || children);
151+
} else {
152+
this.routes = [];
153+
}
152154

153155
if (history) {
154156
this.updateHistory(history);

modules/__tests__/serverRendering-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('server rendering', function () {
3030
it('works', function (done) {
3131
var location = createLocation('/');
3232

33-
Router.run(routes, location, function (error, state, transition) {
34-
var string = React.renderToString(<Router {...state} />);
33+
Router.run(routes, location, function (error, state) {
34+
var string = React.renderToString(<Router initialState={state} />);
3535
expect(string).toMatch(/The Dashboard/);
3636
done();
3737
});

0 commit comments

Comments
 (0)