问题
I've installed the react-navigation
module inside the project's folder:
~/react-tutorial/react-native/Project1$ npm install --save react-navigation
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
- react-navigation@3.3.2 added 22 packages from 10 contributors and audited 103279 packages in 43.188s found 11 low severity vulnerabilities run
npm audit fix
to fix them, ornpm audit
for details
But when I try to include StackNavigator
in the Component with import { StackNavigator } from 'react-navigation';
I've got the following error in the browser when debugging remotely
TypeError: bundle.modules is undefined
回答1:
In the new react-native
version there is change in react-navigation
. StackNavigator
has been replaced by createStackNavigator
.
You have to also install react-native-gesture-handler
along with react-navigation.
(commands below)
npm install --save react-native-gesture-handler // install
react-native link react-native-gesture-handler // link
I will help with some syntax below
old version below -
import { StackNavigator } from 'react-navigation';
const PrimaryNav = StackNavigator({
Splash: { screen: Splash },
Login: { screen: Login },
}, {
// Default config for all screens
headerMode: 'none',
initialRouteName: 'Splash',
});
New Version below -
import { createAppContainer, createStackNavigator } from 'react-navigation';
const MainNavigator = createStackNavigator({
Splash: { screen: Splash }
},
{
// Default config for all screens
headerMode: 'none',
initialRouteName: 'Splash'
});
const PrimaryNav = createAppContainer(MainNavigator);
来源:https://stackoverflow.com/questions/54876365/how-to-add-react-navigation-module-to-reactive-app