Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
701 views
in Technique[技术] by (71.8m points)

react native - Get "Cannot read property 'navigate' of undefined" when I´m logged in with backend

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
...