React Navigation跨导航器跳转报错:Navigate with payload未被处理
解决跨导航容器的页面跳转错误问题
你的问题出在使用了两个独立的NavigationContainer(都设置了independent={true}),这会让BottomTab Navigator的导航上下文和外层Stack Navigator完全隔离,导致内部页面的navigation对象找不到外层Stack里的Savepost路由,从而触发"Navigate with payload was not handled by any navigator"错误。
修复步骤:
- 移除BottomTab外层的独立导航容器
嵌套导航器不需要单独包裹NavigationContainer,直接保留BottomTab.Navigator即可,让它继承外层Stack的导航上下文。修改后的MainScreen代码:
const MainScreen = () => { return ( <BottomTab.Navigator screenOptions={{ tabBarStyle: { backgroundColor: "black" }, headerShown: false, tabBarActiveTintColor: "white", tabBarHideOnKeyboard: true }} > <BottomTab.Screen name="NewVideo" component={Newpost} /> // 其他路由 </BottomTab.Navigator> ); };
- 保留外层主导航容器
外层的NavigationContainer保持不变,它作为整个应用的根导航上下文,负责管理所有顶层路由(包括Home、Savepost等)。
完成以上修改后,NewVideo页面里的navigation.navigate('Savepost', { source: result.assets })就能正确找到外层Stack中的Savepost页面,完成带参数的跳转。
额外说明:
independent={true}仅适用于需要完全独立导航树的场景(比如弹窗内的独立导航),普通的嵌套导航不要开启该属性,否则会切断导航上下文的传递,导致跨导航器跳转失败。
内容的提问来源于stack exchange,提问作者oussamaZAAM
相关产品推荐
相关产品推荐

