Skip to content

Commit

Permalink
[added] initialPath prop to <Routes>
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jul 27, 2014
1 parent 3aa29ff commit b0aa491
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions modules/components/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var Routes = React.createClass({
},

propTypes: {
initialPath: React.PropTypes.string,
location: React.PropTypes.oneOf([ 'hash', 'history' ]).isRequired,
},

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

getInitialState: function () {
return {};
return {
path: this.props.initialPath,
matches: []
};
},

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

componentDidMount: function () {
this.dispatch(URLStore.getCurrentPath());
this.dispatch(this.state.path || URLStore.getCurrentPath());
},

componentWillUnmount: function () {
Expand Down Expand Up @@ -174,16 +178,12 @@ var Routes = React.createClass({
},

render: function () {
if (!this.state.path)
return null;

var matches = this.state.matches;
if (matches.length) {
// matches[0] corresponds to the top-most match
return matches[0].route.props.handler(computeHandlerProps(matches, this.state.activeQuery));
} else {

if (matches.length === 0)
return null;
}

return getRootMatch(matches).route.props.handler(computeHandlerProps(matches, this.state.activeQuery));
}

});
Expand Down

0 comments on commit b0aa491

Please sign in to comment.