我需要将同一个屏幕的多个示例推送到堆栈中,而.navigate()无法实现这一点,它只是导航到已经在堆栈中的示例(与no-op相同)。.push已从navigation和CommonActions(以前为StackActions)中删除。
.navigate()
.push
navigation
CommonActions
StackActions
mcvgt66p1#
我自己找到了答案:
import { CommonActions } from "@react-navigation/native"; const state = navigation.getRootState().state; const routes = state.routes; routes.push({ key: `ScreenName-${uniqueKey}`, name: "ScreenName", params: screenNameNavProps, }); navigation.dispatch(CommonActions.reset({ ...state, index: state.index + 1, routes });
确保将ScreenName更改为您的屏幕名称,并为uniqueKey分配一个唯一的键(我使用了屏幕导航属性中的唯一键)。
ScreenName
uniqueKey
1条答案
按热度按时间mcvgt66p1#
我自己找到了答案:
确保将
ScreenName
更改为您的屏幕名称,并为uniqueKey
分配一个唯一的键(我使用了屏幕导航属性中的唯一键)。