React에서 왔으면 Navigator라 쓰고 Router라 읽자.

import * as React from 'react';
import { View, Text } from 'react-native';
**import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';**

function HomeScreen() {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
    </View>
  );
}
function DetailsScreen() {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Detail Screen</Text>
    </View>
  );
}

**const Stack = createStackNavigator();**

function App() {
  return (
    **<NavigationContainer>
			<Stack.Navigator initialRouteName="Home">
        <Stack.Screen name="Home" component={HomeScreen} options={{ title: 'Overview' }}/>
				<Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>**
  );
}

export default App;
  1. name, component 는 필수
  2. initialRouteName 으로 디폴트 route를 설정
  3. options 로 Header의 UI 설정

Navigator 구조화 하기.


const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();

function Home() {
  return (
    <Tab.Navigator>
      <Tab.Screen name="Feed" component={Feed} />
      <Tab.Screen name="Messages" component={Messages} />
    </Tab.Navigator>
  );
}

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={Home} />
        <Stack.Screen name="Profile" component={Profile} />
        <Stack.Screen name="Settings" component={Settings} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

NEXT STEP

Navigate(화면 이동)