react-native-router-flux如何拿到上一页的参数
时间: 2023-08-14 20:04:38 浏览: 59
如果你想在 `react-native-router-flux` 中拿到上一页的参数,可以使用以下方法:
1. 在上一页中使用 `Actions.currentScene` 获取当前场景的名称。
2. 使用 `Actions.getSceneProps(sceneName)` 获取指定场景的参数。
例如,在上一页中,你可以这样定义场景:
```javascript
import { Actions } from 'react-native-router-flux';
class PreviousPage extends Component {
onNextPagePress = () => {
const param = { name: 'John', age: 25 };
Actions.nextPage(param);
};
render() {
return (
<View>
<Button title="Next Page" onPress={this.onNextPagePress} />
</View>
);
}
}
export default PreviousPage;
```
然后在下一页中,你可以这样获取上一页的参数:
```javascript
import { Actions } from 'react-native-router-flux';
class NextPage extends Component {
render() {
const { name, age } = Actions.getSceneProps('previousPage');
return (
<View>
<Text>{`Name: ${name}`}</Text>
<Text>{`Age: ${age}`}</Text>
</View>
);
}
}
export default NextPage;
```
这样就可以在下一页中获取到上一页传递的参数了。