React Native Expo Vibe Coding:路由与权限配置模板
基于 Expo Router 与 EAS 的跨端 App 开发模板,实现类型安全与原生权限自动化配置。

量化可完成度
整体完成度为 83%,AI 在生成路由结构和类型定义方面表现优异,但在处理复杂的原生权限冲突或特定设备适配时可能需要人工干预。
四维达成明细
文件路由规则清晰,AI 能准确生成动态路由和分组结构,减少手动配置错误。
自动应用 userInterfaceStyle: automatic,但安全区(SafeArea)处理需结合 expo-secure-store 或特定 UI 库验证。
权限声明在 config 中集中管理,但运行时权限请求逻辑需额外代码实现,AI 易遗漏动态检查。
EAS 配置标准化程度高,但不同平台的签名证书管理仍需人工介入以确保安全。
人工把关检查点
开发者必须手动审核 app.config.ts 中的权限描述文案是否符合 App Store/Google Play 审核政策,并确认 EAS projectId 配置正确。
升级 / 降级路径
若预算有限,可降级为本地构建或使用 Expo Go 进行开发;若需更高级的 CI/CD,可集成 GitHub Actions 触发 EAS Build。
适用场景与前提
适用于希望快速搭建跨端移动应用的开发者,需具备 Node.js 环境与 Expo CLI。理想场景包括需要频繁迭代 UI 界面、处理原生权限(如相机)以及依赖 CI/CD 自动构建的团队项目。
可直接复制的工程配置
定义 Cursor AI 在 Expo Router 文件路由开发中的核心规则,确保类型安全与目录结构规范。
---
description: Expo Router file-based routing rules for React Native
alwaysApply: true
---
# Expo Router Rules
1. Use `app/` directory for all routes. Do not use manual navigation stacks.
2. Dynamic routes must be named `[slug].tsx` or `(group)/[id].tsx`.
3. Always import `expo-router` components (`Stack`, `Tabs`, `Link`) instead of `react-navigation` directly.
4. Ensure TypeScript strict mode is enabled in `tsconfig.json`.
5. Handle deep linking via `scheme` in `app.config.ts` and use `useRouter()` for programmatic navigation.
6. Group routes using parentheses `(group)` to hide them from URL structure but keep them in the stack.配置 Expo 应用元数据、原生权限声明及 EAS 构建环境变量,确保 iOS/Android 适配与商店审核合规。
import { ExpoConfig, ConfigContext } from 'expo/config';
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: "VibeApp",
slug: "vibe-app",
scheme: "vibeapp",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/icon.png",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff"
},
assetBundlePrefix: "vibeapp",
plugins: [
["expo-camera", { cameraPermission: "用于拍摄内容" }],
["expo-notifications", { androidMode: "transparent" }]
],
extra: {
eas: {
projectId: "YOUR_PROJECT_ID"
}
},
ios: {
bundleIdentifier: "com.example.vibeapp",
supportsTablet: true,
infoPlist: {
NSCameraUsageDescription: "需要访问相机以拍摄照片",
NSPhotoLibraryUsageDescription: "需要访问相册以选择图片"
}
},
android: {
package: "com.example.vibeapp",
permissions: ["CAMERA", "NOTIFICATIONS"]
}
});AI Vibe Coding 四步实战
- 1
初始化 Expo Router 项目结构
目标: 创建符合文件路由规范的目录骨架,确保 TypeScript 类型安全。
PromptCreate a new Expo project with Expo Router. Ensure `app/` directory exists. Add a `(tabs)` group with `home.tsx` and `settings.tsx`. Use strict TypeScript types for route params.验收标准:
Run `npx expo start` and verify that the router generates correct links in `expo-router` dev tools. - 2
配置原生权限与主题
目标: 在 app.config.ts 中声明相机权限并启用自动深浅色模式。
PromptUpdate app.config.ts to include `expo-camera` plugin with permission string. Set `userInterfaceStyle` to 'automatic'. Ensure iOS Info.plist keys are generated correctly.验收标准:
Run `npx expo prebuild` and check `ios/Info.plist` for NSCameraUsageDescription. - 3
实现安全区与手势导航
目标: 添加 SafeAreaProvider 和 Gesture Handler,确保 UI 在刘海屏上正常显示。
PromptAdd `expo-secure-store` and `react-native-gesture-handler`. Wrap the root layout in `SafeAreaProvider`. Implement a simple swipe gesture on the home screen.验收标准:
Run the app on a simulator with notch and verify content does not overlap system bars. - 4
配置 EAS Build 与审核
目标: 设置 EAS projectId 并生成构建配置文件,准备云构建。
PromptInitialize EAS project. Create `eas.json` with development, preview, and production profiles. Ensure `app.config.ts` extra.eas.projectId is set.验收标准:
Run `npx eas build --profile development --platform ios` (dry run) to check config validity.
常见踩坑与解法
- Expo Router 动态路由命名错误导致类型推断失败:确保使用 `[slug].tsx` 而非 `slug.tsx`。
- 原生权限在开发模式与生产模式行为不一致:需在代码中显式处理 `expo-permissions` 或 `expo-camera` 的运行时请求。
- EAS 构建缓存导致旧配置生效:修改 app.config.ts 后需执行 `npx expo prebuild --clean` 以重新生成原生工程。
常见问题
Expo Router 如何处理嵌套路由?
使用括号 `(group)` 创建逻辑分组,这些目录不会出现在 URL 中但会保留在导航栈中。动态参数通过 `[param].tsx` 定义。
为什么 app.config.ts 中的权限描述在 iOS 上无效?
iOS 权限描述必须写入 Info.plist。Expo 会自动从 config 生成,但需确保运行 `expo prebuild` 或重新安装应用以刷新原生层配置。
EAS Build 失败时如何调试?
检查 `eas.json` 中的 profile 设置和 `app.config.ts` 中的 projectId。查看 EAS 控制台日志,通常错误源于签名证书缺失或依赖版本冲突。


