I have a menu in my app with 4 buttons to navigate between the pages. But when i log in with backend and get a user I can′t navigate between the pages anymore! why is there a difference? "Cannot read property 'navigate' of undefined"
This a part of my App.js (this is only the relevant code for what I′m asking):
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import 'react-native-gesture-handler';
const reducer = combineReducers({ user: user.reducer });
const store = configureStore({ reducer });
const Stack = createStackNavigator();
const App = () => {
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator initialRouteName="HomeActivity"
screenOptions={{ headerShown: false }} initialRouteName="Home">
<Stack.Screen
name="Profile"
component={Profile}
/>
<Stack.Screen
name="HomePage"
component={HomePage} />
<Stack.Screen
name='Diary'
component={Diary}
/>
and here is one of the pages where you should be able to navigate from (this is only the relevant code for what I am asking) :
const Profile = ({ navigation }) => {
return (
<>
<Main>
<HeaderContainer>
<HeaderText>
Profil
</HeaderText>
<TouchableOpacity onPress={() => navigation.navigate('HomePage')}>
<Header />
</TouchableOpacity>
</HeaderContainer>
And this error in the console:
enter image description here
question from:
https://stackoverflow.com/questions/66051302/get-cannot-read-property-navigate-of-undefined-when-i%c2%b4m-logged-in-with-backe 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…