使用 expo router 将 1 个参数传递给多个屏幕(React Native 帮助)

问题描述 投票:0回答:0

我正在尝试将相同的参数传递给两个不同的屏幕,我正在使用 expo router,我该如何实现?

这是我尝试过的,但它只传递给“客人”参数到

searchResult
屏幕而不是
searchResultMap
屏幕。

<Pressable onPress={() => router.push(
    {pathname: '/home/explore/searchResult', params: {guests: adults + children}},
    {pathname: '/home/explore/searchResultMap', params: {guests: adults + children}})} 
    style={{marginBottom: 20, alignItems: 'center', justifyContent: 'center', backgroundColor:         '#f15454',height: 50, marginHorizontal: 30, borderRadius: 10 }}>
    <Text style={{fontSize: 20, color: 'white', fontWeight: 'bold'}} >Search</Text>
</Pressable>
 

试过这个:

<Pressable onPress={() => router.push(
    {pathname: '/home/explore/searchResult', params: {guests: adults + children}},
    {pathname: '/home/explore/searchResultMap', params: {guests: adults + children}})} 
    style={{marginBottom: 20, alignItems: 'center', justifyContent: 'center', backgroundColor:         '#f15454',height: 50, marginHorizontal: 30, borderRadius: 10 }}>
    <Text style={{fontSize: 20, color: 'white', fontWeight: 'bold'}} >Search</Text>
</Pressable>
 

期待客人参数被传递到两个屏幕,所以我可以稍后解构它使用

const { guests } = useSearchParams();

react-native expo react-navigation
© www.soinside.com 2019 - 2024. All rights reserved.