mcpField
R
react-native-navigation

react-native-navigation

github.com/pluginagentmarketplace开发1064 次安装42 周前更新
代码仓库

关于 react-native-navigation

react-native-navigation 面向使用 React Navigation v6+ 和 Expo Router 的 React Native 开发者,讲解导航实现模式。内容涵盖类型安全、常见导航器、深度链接和认证流程。

主要功能

  1. 01React Navigation 的 TypeScript 配置
  2. 02Stack、Tab 和 Drawer 导航器
  3. 03深度链接与通用链接
  4. 04类型安全的屏幕参数
  5. 05认证流程处理

适用场景

  1. 01为 React Native 应用设置导航
  2. 02以类型检查方式传递屏幕参数
  3. 03配置链接以打开指定屏幕
  4. 04在认证流程中保护路由

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-react-native --skill react-native-navigation

安装后在 Claude Code 中输入/react-native-navigation确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
config.yaml
schema.json
references/
GUIDE.md
PATTERNS.md
scripts/
validate.py

详细介绍

React Native 导航技能

学习使用 React Navigation v6+ 和 Expo Router 实现适用于生产环境的导航模式。

前置条件

  • React Native 基础知识(组件、样式)
  • TypeScript 基础知识
  • 了解 React context

学习目标

完成此技能后,你将能够:

  • 使用 TypeScript 设置 React Navigation
  • 实现 Stack、Tab 和 Drawer 导航器
  • 配置深度链接和通用链接
  • 处理身份验证流程
  • 以类型安全的方式在屏幕之间传递参数

涵盖主题

1. 安装
npm install @react-navigation/native @react-navigation/native-stack
npm install react-native-screens react-native-safe-area-context

# For tabs
npm install @react-navigation/bottom-tabs

# For drawers
npm install @react-navigation/drawer react-native-gesture-handler react-native-reanimated
2. Stack 导航器
import { createNativeStackNavigator } from '@react-navigation/native-stack';

type RootStackParamList = {
  Home: undefined;
  Details: { id: string };
};

const Stack = createNativeStackNavigator<RootStackParamList>();

function RootNavigator() {
  return (
    <Stack.Navigator>
      <Stack.Screen name="Home" component={HomeScreen} />
      <Stack.Screen name="Details" component={DetailsScreen} />
    </Stack.Navigator>
  );
}
3. Tab 导航器
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

const Tab = createBottomTabNavigator();

function MainTabs() {
  return (
    <Tab.Navigator>
      <Tab.Screen name="Home" component={HomeScreen} />
      <Tab.Screen name="Profile" component={ProfileScreen} />
    </Tab.Navigator>
  );
}
4. 深度链接
const linking = {
  prefixes: ['myapp://', 'https://myapp.com'],
  config: {
    screens: {
      Home: 'home',
      Details: 'details/:id',
    },
  },
};

<NavigationContainer linking={linking}>
  {/* navigators */}
</NavigationContainer>
5. 类型安全导航
import { useNavigation } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';

type NavigationProp = NativeStackNavigationProp<RootStackParamList>;

function HomeScreen() {
  const navigation = useNavigation<NavigationProp>();

  return (
    <Button
      title="Go to Details"
      onPress={() => navigation.navigate('Details', { id: '123' })}
    />
  );
}

快速入门示例

import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

type RootStackParamList = {
  Home: undefined;
  Details: { id: string; title: string };
};

const Stack = createNativeStackNavigator<RootStackParamList>();

export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

常见错误与解决方案

错误原因解决方案
"Navigator not found"缺少 NavigationContainer将应用封装在 NavigationContainer 中
Params undefined类型不匹配检查 ParamList 类型
Deep link not working配置不匹配验证 linking 路径

验证清单

  • 导航在两个平台上均可正常使用
  • 深度链接可打开正确的屏幕
  • TypeScript 能检测参数错误
  • 身份验证流程可保护路由

用法

Skill("react-native-navigation")

绑定的 Agent:02-react-native-navigation

评论

支持 Markdown