index.js
import React, { Component } from 'react';
import { StatusBar } from 'react-native';
import { Provider, connect } from 'react-redux';
import { NavigationProvider, StackNavigation, NavigationContext } from '@expo/ex-navigation';
import Router from './routers';
import Store from './store/configureStore';
// Store & Router
const navigationContext = new NavigationContext({
router: Router,
store: Store,
})
export default class App extends Component {
render() {
return (
<Provider store={Store}>
<NavigationProvider context={navigationContext}>
<StatusBar barStyle="light-content" />
<StackNavigation initialRoute={Router.getRoute('about')} />
</NavigationProvider>
</Provider>
);
}
}
configureStore.js
import { createNavigationEnabledStore, NavigationReducer } from '@expo/ex-navigation';
import { combineReducers, createStore } from 'redux';
const createStoreWithNavigation = createNavigationEnabledStore({
createStore,
navigationStateKey: 'navigation',
});
const store = createStoreWithNavigation(
combineReducers({
navigation: NavigationReducer,
})
);
export default store;
路由器/ index.js
import React from 'react';
import { createRouter } from '@expo/ex-navigation';
import About from './About';
export default createRouter(() => ({
about: () => About,
}));
在android avd上运行上面的代码时,avd会抛出一个错误:
TypeError:undefined不是对象(评估'navigationState.navigators')
下面的详细错误:
TypeError: undefined is not an object (evaluating 'navigationState.navigators')
This error is located at:
in Connect(FocusableComponent(ExNavigationStack)) (at ExNavigationConnect.js:42)
in ExNavConnect (at ExNavigationComponents.js:114)
in ExNavigatorComponent(ExNavigatorComponent) (at index.js:23)
in RCTView (at View.js:113)
in View (at ExNavigationProvider.js:74)
in ExNavigationProvider (at index.js:21)
in Provider (at index.js:20)
in App (at App.js:7)
in App (created by AwakeInDevApp)
in RCTView (at View.js:113)
in View (created by AwakeInDevApp)
in AwakeInDevApp (at registerRootComponent.js:34)
in RootErrorBoundary (at registerRootComponent.js:33)
in ExpoRootComponent (at renderApplication.js:35)
in RCTView (at View.js:113)
in View (at AppContainer.js:102)
in RCTView (at View.js:113)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:34)
- node_modules/@expo/ex-navigation/src/ExNavigationComponents.js:33:20 in getStateForNavigatorId
运行时环境:
Android模拟器Google Pixel XL
sdk版本27
react-native:0.50.3
反应:16.0.0
@ expo / ex-navigation:4.2.0
世博会:23.0.6
如何解决上面的错误?
感谢