Skip to content

Commit b0aa491

Browse files
committed
[added] initialPath prop to <Routes>
Fixes #111
1 parent 3aa29ff commit b0aa491

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

modules/components/Routes.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var Routes = React.createClass({
5858
},
5959

6060
propTypes: {
61+
initialPath: React.PropTypes.string,
6162
location: React.PropTypes.oneOf([ 'hash', 'history' ]).isRequired,
6263
},
6364

@@ -68,7 +69,10 @@ var Routes = React.createClass({
6869
},
6970

7071
getInitialState: function () {
71-
return {};
72+
return {
73+
path: this.props.initialPath,
74+
matches: []
75+
};
7276
},
7377

7478
componentWillMount: function () {
@@ -83,7 +87,7 @@ var Routes = React.createClass({
8387
},
8488

8589
componentDidMount: function () {
86-
this.dispatch(URLStore.getCurrentPath());
90+
this.dispatch(this.state.path || URLStore.getCurrentPath());
8791
},
8892

8993
componentWillUnmount: function () {
@@ -174,16 +178,12 @@ var Routes = React.createClass({
174178
},
175179

176180
render: function () {
177-
if (!this.state.path)
178-
return null;
179-
180181
var matches = this.state.matches;
181-
if (matches.length) {
182-
// matches[0] corresponds to the top-most match
183-
return matches[0].route.props.handler(computeHandlerProps(matches, this.state.activeQuery));
184-
} else {
182+
183+
if (matches.length === 0)
185184
return null;
186-
}
185+
186+
return getRootMatch(matches).route.props.handler(computeHandlerProps(matches, this.state.activeQuery));
187187
}
188188

189189
});

0 commit comments

Comments
 (0)