如何通过静态导航选项将道具从上一个屏幕传递到下一个屏幕?

How to pass props from previous screen to next screen through static navigationOptions?

我有这样的屏幕转换:

A -> B -> C

现在在 B 上,我有这个 static navigationOptions:

class ScreenB extends Component {

    static navigationOptions = ({navigation}) => ({

    /* works fine to display props here -> */   title: navigation.state.params.MyString, // works fine for display
                                                headerLeft: <Button title="<" onPress={() => navigation.goBack()} />, 
    /* does not work to pass it here -> */      headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {navigation.state.params.MyString})} />
                                } );

    // ...
}

我从A收到MyString,并在B中正常显示。但我想在单击 headerRight 按钮时将其传递给 C。其定义的语法错误为:

Unexpected token, expected ,

会出现什么问题?谢谢

更改此行:

headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {navigation.state.params.MyString})} />

对于:

headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {title:navigation.state.params.MyString})} />

您缺少钥匙。