【问题标题】:Invariant Violation: The navigation prop is missing for this navigator. error on expo不变违规:此导航器缺少导航道具。博览会上的错误
【发布时间】:2019-12-08 09:26:06
【问题描述】:

我的问题与this one 相同,但如果我使用这样的商店提供商,我该怎么办:

const AppNavigator = createSwitchNavigator(
   {
      Loading: MainLoadingScreen,
      App: MainNavigator,
      Auth: AuthStack,
      Signup: SignupStack
   },
   {
      initialRouteName: 'Loading',
   }
);



const App = () => {
  return (
    <Provider store={store}>
      <View style={styles.container}>
        <AppNavigator />
      </View>
    </Provider>
  );
};

export default App;

我收到此错误: 不变违规:此导航器缺少导航道具。在 react-navigation 3 中,您必须直接设置您的应用容器。更多信息:https://reactnavigation.org/docs/en/app-containers.html

此错误位于:

    in Navigator (at App.js:114)
    in RCTView (at View.js:45)
    in View (at App.js:113)
    in Provider (at App.js:112)
    in App (at withExpoRoot.js:20)
    in RootErrorBoundary (at withExpoRoot.js:19)
    in ExpoRootComponent (at renderApplication.js:35)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:34)
- node_modules\@react-navigation\core\lib\module\navigators\createNavigator.js:1:1637 in getDerivedStateFromProps
- node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js:6896:46 in applyDerivedStateFromProps
- ... 20 more stack frames from framework internals

如何转换我的代码以便使用此处显示的格式? :

const App = createAppContainer(AppNavigator)

【问题讨论】:

    标签: react-native react-navigation expo


    【解决方案1】:

    使其成为一个函数并将其分配给Const的值。

    const App = function Appfunc() {
      return (
         <Provider store={store}>
          <View style={styles.container}>
            <AppNavigator />
          </View>
        </Provider>
      );
    }
    
    const AppContainer = createAppContainer(AppNavigator)
    
    export default AppContainer
    

    【讨论】:

    • 但它已经是一个箭头函数了。如何将它与将 switchnavigator 分配给 createAppContainer 结合使用?
    • 像你的问题那样做是对的。看我的回答。箭头功能可能无法正常工作。试试我的答案。
    【解决方案2】:

    createAppContainer包裹你的开关导航器:

    const MainSwitch = createSwitchNavigator(
       {
          Loading: MainLoadingScreen,
          App: MainNavigator,
          Auth: AuthStack,
          Signup: SignupStack
       },
       {
          initialRouteName: 'Loading',
       }
    );
    
    const AppNavigator = createAppContainer(MainSwitch)
    
    export default App = () => {
      return (
        <Provider store={store}>
          <View style={styles.container}>
            <AppNavigator />
          </View>
        </Provider>
      );
    };
    

    【讨论】:

      猜你喜欢
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2020-05-29
      • 2019-08-27
      • 2019-09-11
      • 1970-01-01
      • 2021-08-29
      相关资源
      最近更新 更多