Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add initialRouteStack feature
  • Loading branch information
liuyaodong committed Dec 15, 2015
commit d2979d6fec3c530023ac9f44b03e4f06ae77fb83
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ class Router extends React.Component {
super(props);
this.routes = {};
this.schemas = {...props.schemas};
this.initial = props.initial;
this.initial = this.props.initialRoutes || []; // Initial names array

const self = this;
React.Children.forEach(this.props.children, function (child, index) {
Expand All @@ -468,8 +468,8 @@ class Router extends React.Component {
React.Children.forEach(this.props.children, function (child, index) {
const name = child.props.name;
if (child.type.prototype.className() === "Route") {
if (child.props.initial || !self.initial) {
self.initial = name;
if (child.props.initial) {
self.initial.push(name);
}
// declare function with null navigator to avoid undefined Actions
Actions.addAction(name, child.props, self.schemas, self)
Expand All @@ -496,12 +496,12 @@ class Router extends React.Component {
}

render(){
if (!this.state.initial){
if (!this.state.initial.length){
console.error("No initial attribute!");
}
const initialRoute = this.routes[this.state.initial];
if (!initialRoute) {
console.error("No initial route!"+JSON.stringify(this.routes));
const initialRoutes = this.state.initial.map((name) => this.routes[name]);
if (!initialRoutes.length) {
console.error("No initial routes!"+JSON.stringify(this.routes));
}

const Header = this.props.header;
Expand All @@ -514,7 +514,7 @@ class Router extends React.Component {
<View style={styles.transparent}>
{header}
<ExNavigator ref="nav"
initialRoute={new ExRoute(initialRoute, this.schemas)}
initialRouteStack={initialRoutes.map((route) => new ExRoute(route, this.schemas))}
style={styles.transparent}
sceneStyle={{ paddingTop: 0 }}
showNavigationBar={!this.props.hideNavBar}
Expand Down