在反应导航中使用 navigation.goBack 发送参数

Har*_*ana 6 react-native react-redux react-navigation

你好,如何发送导航返回参数?

const Onsubmit = (data, details = null) => {
    console.log(details.formatted_address);
    route.params.onPlaceChosen(
      route.params.id,
      details.formatted_address,
      details.geometry
    );
    navigation.goBack();
  };
Run Code Online (Sandbox Code Playgroud)

这里我想将details.formatted_address中的值传递到页面B。如何?

Nos*_*omo 3

如果您从屏幕 A 导航到屏幕 B,并且当您想返回屏幕 A 并再次在屏幕 A 中运行回调时,您需要执行以下操作:

在你的屏幕 A(来源)中

...
const onPlaceChosen = (params) => {
    // here is your callback function
}

...
navigation.navigate('ScreenB', { onPlaceChosen })
...
Run Code Online (Sandbox Code Playgroud)

在您的屏幕 B(目的地)中

..
const Onsubmit = (data, details = null) => {

    navigation.state.params.onPlaceChosen(
      route.params.id,
      details.formatted_address,
      details.geometry
    );
    navigation.goBack();
  };
...
Run Code Online (Sandbox Code Playgroud)

  • 将函数作为参数传递时收到警告。 (7认同)
  • 它是“this.props.route.params”。答案来自:/sf/answers/4288270031/ (2认同)