화면 간 이동과 매개변수 전달
navigation.navigate로 화면 사이를 이동하고 두 번째 인수로 매개변수를 전달하며, 대상 화면에서 route.params로 매개변수를 읽습니다.
화면 간 이동과 매개변수 전달은(는) CoddyKit의 무료 React Native Academy 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 React Native Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
The navigation Prop in Screens
Every component registered as a screen in a React Navigation navigator automatically receives a navigation prop. This object provides methods to move between screens, go back, and manage the navigation stack. You can also access it in nested components using the useNavigation hook.
function HomeScreen({ navigation }) {
// navigation.navigate, navigation.goBack, etc.
return <View />;
}Navigating with navigation.navigate
Call navigation.navigate('ScreenName') to move to another screen. If the screen is already in the stack and you navigate to it again, React Navigation will go to the existing instance rather than adding a duplicate. Use navigation.push('ScreenName') to always push a new instance.
function HomeScreen({ navigation }) {
return (
<Button
title='Go to Details'
onPress={() => navigation.navigate('Details')}
/>
);
}Going Back with navigation.goBack
Call navigation.goBack() to pop the current screen off the stack and return to the previous one. On iOS the swipe-back gesture is enabled by default. On Android, the hardware back button calls goBack automatically. Use navigation.popToTop() to jump all the way back to the first screen.
function DetailsScreen({ navigation }) {
return (
<Button
title='Go Back'
onPress={() => navigation.goBack()}
/>
);
}Passing Params When Navigating
Pass a second argument to navigation.navigate to send parameters to the destination screen. The params object can contain any serializable data — IDs, strings, booleans. Avoid passing complex non-serializable objects like class instances or functions.
function HomeScreen({ navigation }) {
return (
<Button
title='View Post'
onPress={() =>
navigation.navigate('Details', {
postId: 42,
title: 'React Navigation Deep Dive',
})
}
/>
);
}Reading Params with route.params
The destination screen receives a route prop alongside the navigation prop. Access the parameters you passed via route.params. Always provide defaults in case a screen is opened without params, for example when it is the initial screen.
function DetailsScreen({ route, navigation }) {
const { postId, title } = route.params ?? {};
return (
<View>
<Text>Post ID: {postId}</Text>
<Text>Title: {title}</Text>
</View>
);
}Default Params on Stack.Screen
Set initialParams on a Stack.Screen to provide default parameter values. These defaults merge with any params passed at runtime, so the screen always has a complete set of values to work with, even when opened as the initial route.
<Stack.Screen
name='Details'
component={DetailsScreen}
initialParams={{ postId: 0, title: 'Unknown' }}
/>Updating Params from a Screen
A screen can update its own params using navigation.setParams. This is useful when an action on the current screen (like editing a form field) should be reflected in the navigation header title. The params update triggers a re-render of the screen.
function DetailsScreen({ route, navigation }) {
const { title } = route.params;
return (
<Button
title='Update Title'
onPress={() => navigation.setParams({ title: 'Updated Title' })}
/>
);
}Using useNavigation Hook
Deep child components that are not registered screens do not receive the navigation prop automatically. Use the useNavigation() hook from React Navigation to access the navigation object anywhere inside the navigator tree without prop drilling.
import { useNavigation } from '@react-navigation/native';
function MyButton() {
const navigation = useNavigation();
return (
<Button
title='Go to Profile'
onPress={() => navigation.navigate('Profile')}
/>
);
}Using useRoute Hook
Similarly, use the useRoute() hook to access route.params in a non-screen component. This is useful when you have a deeply nested component that needs to read the current screen's parameters without threading the route prop through every level.
import { useRoute } from '@react-navigation/native';
function PostHeader() {
const route = useRoute();
const { title } = route.params ?? {};
return <Text style={{ fontWeight: 'bold' }}>{title}</Text>;
}Setting the Header Title from Params
You can dynamically set the navigation header title based on route params by passing a function to the options prop. The function receives the route object, allowing you to use param values as the screen title without extra state.
<Stack.Screen
name='Details'
component={DetailsScreen}
options={({ route }) => ({ title: route.params.title ?? 'Details' })}
/>Navigating Back and Sending Data Back
To send data from a child screen back to its parent, use navigation.navigate with the parent screen's name and include the return data as params. The parent screen will receive the updated params. Alternatively, pass a callback function as a param to the child screen and call it before going back.
// In child screen
navigation.navigate('Home', { selectedItem: 'apple' });
// In parent screen — read route.params.selectedItemQuick Check
Test your understanding of React Navigation screen navigation and params from this lesson.
Lesson Recap
In this lesson you learned: use navigation.navigate to move to another screen, pass params as the second argument to navigate, and read params with route.params in the destination screen. Next up we explore the Bottom Tab Navigator.
자주 묻는 질문
“화면 간 이동과 매개변수 전달” 강의는 무료인가요?
네 — “화면 간 이동과 매개변수 전달” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 React Native Academy 강의 전체를 잠금 해제할 수 있습니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“화면 간 이동과 매개변수 전달”에서 뭘 배우나요?
navigation.navigate로 화면 사이를 이동하고 두 번째 인수로 매개변수를 전달하며, 대상 화면에서 route.params로 매개변수를 읽습니다. 브라우저에서 직접 실행하는 실습 코드로 React Native Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
React Native Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 React Native Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“화면 간 이동과 매개변수 전달” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 React Native Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 React Native Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- React Navigation 설치 및 구성
- 화면 간 이동과 매개변수 전달
- 하단 탭 내비게이터
- 서랍 내비게이터와 중첩 내비게이터