React Native - 导航到子组件时出错

时间:2016-11-15 16:27:54

标签: react-native

我能够定义初始路线(Home)并且应用程序导航到该路线。 Inside Home我正在调用另一个名为BoxLists的组件,它按预期显示。我遇到的问题是从BoxLists中调用另一个名为StationOne的组件。

我收到以下错误:未捕获错误:undefined不是对象(评估'this.props.navigator.push'

所以问题是:我如何从BoxLists导航到StationOne?

注意:我打算从BoxLists导航到其他组件(StationOne,StationTwo,StationN + 1)。

虽然您可以在https://rnplay.org/apps/rLB5HQ转到RNPlayground,但这是代码。谢谢!

class App extends React.Component {
 navigatorRenderScene(route,navigator){
 if (route.title == "Home")
  { 
   return( <Home navigator={navigator} /> ); 
  }
 if (route.title == "StationOne")
  { 
   return( <StationOne navigator={navigator} /> );  
  }
}

 render() {
  return (
   <Navigator
     initialRoute = {{ title: "Home" }}
     renderScene = {this.navigatorRenderScene.bind(this)}
   />
  );
 }
}

 class Home extends React.Component {
  render() {
    return (      
     <View style={{flex: 1}}>
       <View style={styles.header}>
         <Text style={styles.headerText}>AdView</Text>
       </View>
      <BoxLists author="station one" navigator={navigator} />
     </View>            
   );
  }
 }

 class BoxLists extends React.Component {
  _goToStation(){
    this.props.navigator.push({
     title: 'StationOne'
    });
  } 

  render() {
    return (
     <View>
       <Text>You are in BoxList. The passed prop is: {this.props.author}</Text>
         <TouchableHighlight onPress={this._goToStation.bind(this)}>
            <Text>Press here to go to StationOne</Text>
         </TouchableHighlight>
     </View>
   );
  }
 }

 class StationOne extends React.Component {
  render() {
    return (      
     <View style={{flex: 1}}>
      <Text> This is station one </Text>
     </View>            
    );
   }
  }

1 个答案:

答案 0 :(得分:0)

java.security.KeyStore

您需要为BoxLists组件传递this.props.navigator,如上所示