以下代码在我的Expo React Native项目中运行良好:

const AppNavigator = createSwitchNavigator({
    Loading:Loading,
    Auth: AuthenticationNavigator,
    Main: MainNavigator
});

const AppContainer = createAppContainer(AppNavigator);

class App extends React.Component {
    render() {
        return <AppContainer/>
    }
}


我想将screenProps添加到我的createSwitchNavigator中。我使用了this example。这是我的代码:

const AppNavigator = createSwitchNavigator({
    Loading:Loading,
    Auth: AuthenticationNavigator,
    Main: MainNavigator
});
const AppNavigatorWithProps=(<AppNavigator screenProps={{testing:true}} />)

const AppContainer = createAppContainer(AppNavigatorWithProps);

class App extends React.Component {
    render() {
        return <AppContainer/>
    }
}


我收到以下错误:

TypeError: undefined is not an object (evaluating 'Component.router.getStateForAction')

This error is located at:
    in NavigationContainer (at App.js:42)
    in App (at withExpoRoot.js:22)
    in RootErrorBoundary (at withExpoRoot.js:21)
    in ExpoRootComponent (at renderApplication.js:34)
    in RCTView (at View.js:44)
    in RCTView (at View.js:44)
    in AppContainer (at renderApplication.js:33)


我究竟做错了什么?

最佳答案

class App extends React.Component {
  render() {
    return <AppContainer screenProps={{ testing: true }} />
   }
 }


像这样

关于javascript - 将 Prop 传递给createSwitchNavigator会破坏createAppContainer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54860261/

10-10 18:52