未定义不是函数('...(0,_reactNavigation.StackNavigator)...'附近)

时间:2019-10-20 05:15:08

标签: react-native react-navigation stack-navigator

我正在用本机做一个研究项目(天气应用程序)。我正在使用react-navigation v4。它给出了上述错误。请任何人帮助解决此问题。

//Index.js

import React from "react";
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { createStore, applyMiddleware } from 'redux';
import reducer from "./reducers";
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';

import { StackNavigator } from 'react-navigation';
import WeatherDetails from './screens/WeatherDetails';
import CityLists from './screens/CityLists';

const Navigation = StackNavigator({
  WeatherDetails: { screen: WeatherDetails },
  CityLists: { screen: CityLists }
});

const store = createStore(reducer, applyMiddleware(thunk));

const wrapper = () => {
  return (
    <Provider store={store}>
      <Navigation />
    </Provider>
  );
}

AppRegistry.registerComponent(appName, () => wrapper);

1 个答案:

答案 0 :(得分:1)

react-navigationv(4.0) documentation中所述,您必须单独安装StackNavigator。因此,首先安装StackNavigator

  

npm install react-navigation-stack --save

然后从createStackNavigator导入react-navigation-stack

import { createStackNavigator } from 'react-navigation-stack';

现在,创建导航:

const Navigation = createStackNavigator ({
  WeatherDetails: { screen: WeatherDetails },
  CityLists: { screen: CityLists }
});