function App() {
return (
<Stack.Navigator initialRouteName=“Login”>
<Stack.Screen options={
{headerShown: false}} name=“Login” component={Login} />
<Stack.Screen name=“Some” component={Some}
options={
{
headerRight: () => (
<Button
onPress={() => alert(‘This is a button!’)}
title=“add”
color=“#999”
/>
),
}}
/>
</Stack.Navigator>
);
}
3. 嵌套导航(Tabs)
3.1 安装依赖
npm install @react-navigation/bottom-tabs // 5.x版本
3.2 Example
// Some.js // 将之前的 Some.js 替换为以下代码
import {createBottomTabNavigator} from ‘@react-navigation/bottom-tabs’;
import * as React from ‘react’;
import { View, Button, Text } from ‘react-native’;
const Tab = createBottomTabNavigator(); //
function HomePage() {
return (
<View
style={
{
flex: 1,
backgroundColor: ‘#ccc’,
justifyContent: ‘center’,
alignItems: ‘center’,
}}>
<Button
title=“Go to Profile”
onPress={() => navigation.push(‘Login’)}
/>
);
}
function Detail({navigation}) {
return (
<View
style={
{
flex: 1,
backgroundColor: ‘#ddd’,
justifyContent: ‘center’,
alignItems: ‘center’,
}}>
);
}
function Mine({navigation}) {
return (
<View
style={
{
flex: 1,
backgroundColor: ‘#ddd’,
justifyContent: ‘center’,
alignItems: ‘center’,
}}>