N
N
Newbie Ivanovich2019-05-24 04:57:11
JavaScript
Newbie Ivanovich, 2019-05-24 04:57:11

How to properly create routes in react-navigation using createStackNavigator?

stacknavigator doesn't work when you navigate, an empty
navigator page pops up:

import {
    createSwitchNavigator,
    createStackNavigator,
    createAppContainer,
    createDrawerNavigator
} from 'react-navigation';
import MenuScreen1 from './screens/Menu1';
import MenuScreen2 from './screens/Menu2';
import Spisok from './screens/Spisok';
import OrderScreen from './screens/OrderScreen'


// const menuStack = createStackNavigator(
//     {
//         Menu1:{
//             screen:MenuScreen1,
//             navigationOptions: () => ({
//                 title:'menu1',
//               }),
//         },
//         Menu2:{
//             screen:MenuScreen2,
//             navigationOptions: () => ({
//                 title:'menu2',
//               }),
//         },
//     }
// );


export default createAppContainer(
    createSwitchNavigator(
        {
            List: Spisok,
            Menu1: MenuScreen1,
            Menu2: MenuScreen2,
            Order: OrderScreen
        },
        {
            initialRouteName: 'List'
        }
    )
);

component from which I pass to another component
import React from 'react';
import { FlatList, Text, View } from 'react-native';
import styles from '../styles'


class Spisok extends React.Component {

  render() {
    return (
      <View>
                <Text onPress={this.menu1} style={ styles.otstup }>Menu1</Text>
                <Text onPress={this.menu2} style={ styles.otstup }>Menu2</Text>
        <Text onPress={this.menu3} style={ styles.otstup }>Заказы</Text>
            </View>
    );
  }

  menu1 = () => {		
    this.props.navigation.navigate('Menu1');
  };
  menu2 = () => {
    this.props.navigation.navigate('Menu2');
  };
  menu3 = () => {
    this.props.navigation.navigate('Order');
  };
}

export default Spisok;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Newbie Ivanovich, 2019-05-24
@NovichokIvanovich

it turned out that everything works. just had to remove the styles in the app.js file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question