Matheus Cabral
Matheus Cabral

Reputation: 182

How to make a route in react native?

The routers Is not working, I tryed many forms but not worked, can someone help me?

the following error is: Device: (487:41) undefined is not an object (evaluating '_this2.props.navigation.navigate')

import { createDrawerNavigator, createAppContainer } from "react-navigation";
import Noturno from './containerNoturno.js';
import Linhas from './Linhas.js';
import LSaida from './LinhasSaida.js';
import Main from './containerDiurno.js';
import Ajuda from './Ajuda.js';
import Sobre from './sobre.js';
import Intro from './intro.js';
import GalopolisSantaCoronaNoturno from './Noturno/GalopolisSantaCorona.js';

const AppNavigator = createDrawerNavigator({
Menu: { screen: Main },
Noturno: { screen: Noturno },
Linhas: { screen: Linhas },
Linhas_Saida: { screen: LSaida },
Ajuda: { screen: Ajuda },
Sobre: { screen: Sobre },
Galopolis_Noturno: { screen: GalopolisSantaCoronaNoturno },
});
export default createAppContainer(AppNavigator);

here is the other code:

  <TouchableOpacity
      onPress={() => this.props.navigation.navigate('Noturno')}
      style={styles.fab}>
      <Image
        source={require('../assets/noite.png')}
        style={{ width: 50, height: 50 }}
      />
    </TouchableOpacity>

Please open the follow link and help me...

Upvotes: 0

Views: 67

Answers (1)

Mehran Khan
Mehran Khan

Reputation: 3636

You are accessing the navigation prop in child component "Noturno.js" which is not part of StackNavigator

You can access the prop like this (Access the navigation prop from any component)

Update file "Noturno.js"

import { withNavigation } from 'react-navigation';

....

class App extends React.Component

....


export default withNavigation(App);


Upvotes: 1

Related Questions