ZhengXingchi / ZhengXingchi.github.io

Apache License 2.0
0 stars 0 forks source link

react-navigation #70

Open gone-with-the-wind opened 4 years ago

gone-with-the-wind commented 4 years ago

参数传递

1.通过将params放入对象作为该navigation.navigate函数的第二个参数,将params传递给路径:this.props.navigation.navigate('RouteName', { / params go here / }) 2.阅读屏幕组件中的参数:this.props.navigation.getParam(paramName, defaultValue)。

//传参
<Button
    style={styles.btn}
    title={'前往navigationScreen3'}
    onPress={() => {
        this.props.navigation.push('navScr3', {pushParam: '你好 我是navigationScreen2'})
    }}
/>
//navigate('模块名', 参数)     push('模块名', 参数)

//解析
const pushParam = this.props.navigation.getParam('pushParam', '你说什么');//第二个参数 是设置默认参数  当读取不到是就读取的这个
<Text style={styles.text}>{pushParam}</Text>

//initialRouteParams - 这个属性可以设置一个初始路线的参数 和initialRouteName在一个地方进行设置
gone-with-the-wind commented 4 years ago

参考文献

React Navigation中文网 不过中文网目前翻译的是React Navigation V1,已经过时了。

最好还是参考英文官方5.0版本

gone-with-the-wind commented 4 years ago

react-navigation与redux的结合

RN学习笔记3-Redux + React Navigation