javascript - 如何在 React Native 中有条件地渲染屏幕但将其放置在堆栈上?
问题描述
我有这个:
const initialRouteName = leagueId ? 'League' : 'Leagues'
return (
<Stack.Navigator initialRouteName={initialRouteName}>
<Stack.Screen
name="Leagues"
>
{(props: any) => <MyLeagues navigation={props.navigation} theme={theme} />}
</Stack.Screen>
<Stack.Screen
name="League"
>
{(props: any) => {
return <League leagueId={leagueId} theme={theme} />
}}
</Stack.Screen>
</Stack.Navigator>
现在这有效(有点)。我已经改变了这种行为,当我使用 PN(如果leagueId
存在)时,它会将用户“导航”到正确的屏幕。
但是,如果您单击启动此堆栈的选项卡,则该行为将返回到Leagues
屏幕。它现在没有这样做,因为我已经将它设置initialRouteName
为League
,所以我猜Leagues
它不在堆栈上。有没有办法确保我League
最初渲染屏幕(如果leagueId
存在)但也允许它返回?如果这有意义
解决方案
推荐阅读
- python - Json 覆盖上一行
- windows - Windows 上的 Kubernetes 错误:无法连接到服务器:dial tcp some ip
- c++ - 用常量数组初始化指向结构的指针
- java - 从 Jetty 类路径中排除特定 Web 应用程序的 lib/ext
- sql - 在 SQL 中,如何选择另一列中没有零值的最新日期
- javascript - 如何使用 axios 将文件从 VueJS 发送到 API/ExpressJS
- r - 是否有 R(ggplot 或其他)来增加线/段宽度
- css - Ant Design Steps 连接器的自定义样式?
- javascript - 最短路径的中继系统(计算起点和终点之间的中继点)
- python - 如何将一个数组附加到另一个数组,同时在 Python 中保持两个数组彼此分开