【问题标题】:The action 'NAVIGATE' with payload {"name":"CoursesPlaylistScreen"} was not handled by any navigator in React native带有有效负载 {"name":"CoursesPlaylistScreen"} 的操作 'NAVIGATE' 未由 React native 中的任何导航器处理
【发布时间】:2021-12-10 17:11:01
【问题描述】:

我已经尝试嵌套导航器,所以我不必面对这个问题,但我仍然收到此错误,因为我有包含第一个屏幕 BootcampWeeksScreen.js 的主导航器,然后我可以轻松地浏览它的新屏幕包含const tab= createMaterialTopTabNavigator()

BootcampWeeksScreen.js:

import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";
import Courses from "./BootcampAdditionalScreens/Courses";
import Tests from "./BootcampAdditionalScreens/Test";
import Roadmap from "./BootcampAdditionalScreens/Roadmap";
import CoursesPlaylistScreen from "../screens/BootcampAdditionalScreens/CoursesPlaylistScreen.js";
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();
const Tab = createMaterialTopTabNavigator();
const BootcampWeeksScreen=()=>{
  return (

    <NavigationContainer>

      <Tab.Navigator tabBarOptions={{ scrollEnabled: true }}>
      <Tab.Screen name="Course" component={Courses} />
      <Tab.Screen name="Tests" component={Tests} />
        <Tab.Screen name="Roadmap" component={Roadmap} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}
 function App() {
    return (
      <NavigationContainer>
        <Stack.Navigator screenOptions={{ headerShown: false }}>
          <Stack.Screen name="BootcampWeeksScreen" component={BootcampWeeksScreen} />
          <Stack.Screen name="CoursesPlaylistScreen" component={CoursesPlaylistScreen} />
        </Stack.Navigator>
      </NavigationContainer>
    );
  }

  export default BootcampWeeksScreen;
  

现在我想从Course 屏幕浏览CoursesPlaylistScreen 屏幕,但我收到此错误,并且我尝试嵌套导航器。

我也尝试过通过屏幕导航:``onPress={() =>navigation.navigate("BootcampStack",{screen:"CoursesPlaylistScreen"})} ```

仍然,我收到此错误。

 ERROR  The action 'NAVIGATE' with payload {"name":"CoursesPlaylistScreen"} was not handled by any navigator.

Do you have a screen named 'CoursesPlaylistScreen'?

If you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-nested-navigator.

我不知道我该怎么做?

【问题讨论】:

  • 我认为你不应该使用 TWO NavigationContainer.const BootcampWeeksScreen=()=>{ return ( ); }
  • @SlavaVasilenko 我试过这个但我收到了一个错误Error: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?
  • 我为您创建了工作示例。我希望这有助于snack.expo.dev/JIbD5QU_Y
  • @SlavaVasilenko 我尝试了您的建议,但出现错误Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of StackNavigator.
  • @SlavaVasilenko 我已经有了exported default我的组件。

标签: javascript reactjs react-native navigation react-navigation


【解决方案1】:

您只能拥有一个 NavigationContainer。尝试从 BootcampWeeksScreen 中删除 NavigationContainer。

【讨论】:

  • 仍然出现同样的错误The action 'NAVIGATE' with payload {"name":"CoursesPlaylistScreen"} was not handled by any navigator.
【解决方案2】:

NavigationContainer 负责管理您的应用状态并将您的顶级导航器链接到应用环境。通过提供两个导航器,您将重置整个导航器,因此无法找到另一个堆栈。

您应该只将您的堆栈包装在导航根/顶层的 NavigationContainer 中,即在您的情况下使用函数 App。

【讨论】:

  • 我试过这个但我收到了一个错误Error: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?
  • 你能告诉我NavigationContainer里面包装了什么吗?
  • 我已将其添加到我的帖子中。请看
猜你喜欢
  • 1970-01-01
  • 2020-08-17
  • 1970-01-01
  • 1970-01-01
  • 2021-12-02
  • 1970-01-01
  • 2020-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多