父类
this.props.navigation.navigate('Child', {
something: 'Some Value',
});
儿童班
this.props.navigation.state.params.something // outputs "Some Value"
但我想得到"某物"作为String
,以便在 if 语句中进行比较。 我应该怎么做?
如果你想访问所有导航参数名称,你可以做const paramNames = Object.keys(this.props.navigation.state.params)
这将是一个像['something', 'anotherParam', 'andAnotherParam']
这样的数组。如果只传递了一个参数,则可以分别使用paramNames[0]
获取其名称