在react native expo中更改屏幕名称

lvmkulzt  于 2023-01-31  发布在  React
关注(0)|答案(1)|浏览(184)

我有以下2个屏幕:

<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="SubScreen1" component={SubScreen1} />

我想将“SubScreen1”的屏幕名称更改为“Search Result”,但出现The action 'NAVIGATE' with payload {"name":"SubScreen1","params":{"paramKey":"Japanese"}} was not handled by any navigator.错误
为什么我有这个错误,因为我有另一个屏幕,我只是改变了名称,没有错误。
在我的主屏幕中:

<View style = {styles.container}>
      <Text>Welcome {auth.currentUser?.email}</Text>
      <Text></Text>
      <Text>What cusine would you like to eat today?</Text>
      <DropDownPicker
      open={open}
      value={value}
      items={items}
      setOpen={setOpen}
      setValue={setValue}
      setItems={setItems}
    />
    
      <TouchableOpacity
        onPress={() => navigation.navigate("SubScreen1", {paramKey:value})}
        style = {styles.button}
      >
        <Text style = {styles.buttonText}>Search</Text>
      </TouchableOpacity>

在我的子屏幕1屏幕中

import { StyleSheet, Text, View } from 'react-native'
import React from 'react'

const SubScreen1 = ({route}) => {
  const paramKey = route.params.paramKey
  console.log(paramKey)
  return (
    <View>
      <Text>{paramKey}</Text>
    </View>
  )
}

export default SubScreen1

const styles = StyleSheet.create({})
cpjpxq1n

cpjpxq1n1#

不确定我是否正确理解了您的问题,但如果您想将屏幕的标题文本更改为“搜索结果”,则只需在Stack.Screenoptions中添加title属性,如下所示

<Stack.Screen
    name="SubScreen1"
    component={SubScreen1}
    options={{ title: 'Search Result' }}
/>

https://reactnavigation.org/docs/headers/#setting-the-header-title

相关问题