Community程式設計與開發github.com

expo/expo-router

框架(開源)。Expo Router 的導航與路由。涵蓋基於檔案的路由、群組與動態路由、資料夾組織、含預覽與上下文選單的 Link、原生 Stack、頁面標題、Modal 與 Form Sheet、NativeTabs、標頭與工具列,以及標頭搜尋列。

expo-router 是什麼?

此技能提供 Expo Router 應用程式的完整導航與路由指南,專注於基於檔案的路由系統。它涵蓋了從基本路由、群組與動態路由、資料夾組織到進階原生導航元件的所有內容,包括 Stack、Modal、Form Sheet 和 NativeTabs。開發人員可以學習如何使用含預覽與上下文選單的 Link 元件來增強使用者體驗,並透過 Stack.Title 設定頁面標題。此技能也詳細說明了標頭與工具列的配置,以及如何透過 Stack.SearchBar 加入搜尋列。所有建議均針對 Expo SDK 56+ 進行最佳化,並強調使用 Expo Router 的 API(而非直接從 @react-navigation/* 匯入)以確保相容性與型別安全。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/expo/skills/tree/main/plugins/expo/skills/expo-router

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Expo Router 導航

Expo Router 應用程式的導航與路由。如需畫面樣式、顏色、控制項、媒體與視覺效果,請使用 expo-native-ui 技能;如需動畫與手勢,請使用 expo-animation。

參考資料

請視需要參考這些資源:

references/
  route-structure.md     Route conventions, dynamic routes, groups, folder organization
  tabs.md                NativeTabs, migration from JS tabs, iOS 26 features
  toolbar-and-headers.md Stack headers and toolbar buttons, menus, search (iOS only)
  form-sheet.md          Form sheets in expo-router: configuration, footers and background interaction.
  search.md              Search bar with headers, useSearch hook, filtering patterns
  zoom-transitions.md    Apple Zoom: fluid zoom transitions with Link.AppleZoom (iOS 18+)

程式碼風格

  • 檔案名稱一律使用 kebab-case,例如 comment-card.tsx
  • 移動或重組導航結構時,務必刪除舊的路由檔案
  • 檔案名稱中切勿使用特殊字元
  • 在 tsconfig.json 中設定路徑別名,重構時優先使用別名而非相對路徑

路由

詳細的路由慣例請參閱 ./references/route-structure.md。

  • 路由應放在 app 目錄中。
  • 切勿在 app 目錄中放置元件、型別或工具函式,這是不良模式。
  • 確保應用程式永遠有一個符合 "/" 的路由,該路由可能位於群組路由內。

函式庫偏好設定

  • 使用 expo-router 中的 Color 來取得原生語義顏色,而非原生的 PlatformColor(型別安全,自動適應明暗模式)。完整的色彩調色盤模式請參閱 expo-native-ui。
  • 在 SDK 56+ 中,請勿直接從 @react-navigation/* 匯入 — 應改用 expo-router/react-navigation(涵蓋 @react-navigation/native、/core、/elements、/routers)。

行為

  • 偏好使用 Stack.SearchBar 為畫面加入搜尋列。

導航

Link

使用來自 'expo-router' 的 <Link href="/path" /> 進行路由間的導航。

import { Link } from 'expo-router';

// 基本連結
<Link href="/path" />

// 包裝自訂元件
<Link href="/path" asChild>
  <Pressable>...</Pressable>
</Link>

只要可能,請加入 <Link.Preview> 以遵循 iOS 慣例。頻繁加入上下文選單與預覽以增強導航體驗。

Stack

  • 一律使用 _layout.tsx 檔案來定義 Stack。
  • 使用來自 'expo-router/stack' 的 Stack 來建立原生導航堆疊。

頁面標題

使用 Stack.Title 設定頁面標題:

<Stack.Title>首頁</Stack.Title>

上下文選單

為 Link 元件加入長按上下文選單:

import { Link } from "expo-router";

<Link href="/settings" asChild>
  <Link.Trigger>
    <Pressable>
      <Card />
    </Pressable>
  </Link.Trigger>
  <Link.Menu>
    <Link.MenuAction
      title="分享"
      icon="square.and.arrow.up"
      onPress={handleSharePress}
    />
    <Link.MenuAction
      title="封鎖"
      icon="nosign"
      destructive
      onPress={handleBlockPress}
    />
    <Link.Menu title="更多" icon="ellipsis">
      <Link.MenuAction title="複製" icon="doc.on.doc" onPress={() => {}} />
      <Link.MenuAction
        title="刪除"
        icon="trash"
        destructive
        onPress={() => {}}
      />
    </Link.Menu>
  </Link.Menu>
</Link>;

Link 預覽

頻繁使用連結預覽以增強導航:

<Link href="/settings">
  <Link.Trigger>
    <Pressable>
      <Card />
    </Pressable>
  </Link.Trigger>
  <Link.Preview />
</Link>

Link 預覽可與上下文選單搭配使用。

Modal

以 Modal 方式呈現畫面:

<Stack.Screen name="modal" options={{ presentation: "modal" }} />

優先採用此方法而非自行建立自訂 Modal 元件。

Sheet

以動態 Form Sheet 方式呈現畫面:

<Stack.Screen
  name="sheet"
  options={{
    presentation: "formSheet",
    sheetGrabberVisible: true,
    sheetAllowedDetents: [0.5, 1.0],
    contentStyle: { backgroundColor: "transparent" },
  }}
/>
  • 使用 contentStyle: { backgroundColor: "transparent" } 可在 iOS 26+ 上營造液態玻璃背景效果。

常見路由結構

一個標準的應用程式佈局,包含標籤頁以及每個標籤頁內的堆疊:

app/
  _layout.tsx — <NativeTabs />
  (index,search)/
    _layout.tsx — <Stack />
    index.tsx — 主列表
    search.tsx — 搜尋檢視
// app/_layout.tsx
import { NativeTabs } from "expo-router/unstable-native-tabs";
import { ThemeProvider, DarkTheme, DefaultTheme } from "expo-router/react-navigation";
import { useColorScheme } from "react-native";

export default function Layout() {
  const colorScheme = useColorScheme();
  return (
    <ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
      <NativeTabs>
        <NativeTabs.Trigger name="(index)">
          <NativeTabs.Trigger.Icon sf="list.dash" md="list" />
          <NativeTabs.Trigger.Label>項目</NativeTabs.Trigger.Label>
        </NativeTabs.Trigger>
        <NativeTabs.Trigger name="(search)" role="search" />
      </NativeTabs>
    </ThemeProvider>
  );
}

建立一個共享的群組路由,讓兩個標籤頁都能推入通用畫面:

// app/(index,search)/_layout.tsx
import { Stack } from "expo-router/stack";
import { colors } from "@/theme/colors";

export default function Layout({ segment }) {
  const screen = segment.match(/\((.*)\)/)?.[1]!;
  const titles: Record<string, string> = { index: "項目", search: "搜尋" };

  return (
    <Stack
      screenOptions={{
        headerTransparent: true,
        headerShadowVisible: false,
        headerLargeTitleShadowVisible: false,
        headerLargeStyle: { backgroundColor: "transparent" },
        headerTitleStyle: { color: colors.label },
        headerLargeTitleEnabled: true,
        headerBlurEffect: "none",
        headerBackButtonDisplayMode: "minimal",
      }}
    >
      <Stack.Screen name={screen} options={{ title: titles[screen] }} />
      <Stack.Screen name="i/[id]" options={{ headerLargeTitleEnabled: false }} />
    </Stack>
  );
}

headerLargeTitleEnabled 是 SDK 56+ 的選項名稱;較舊的 SDK 則使用 headerLargeTitle(已在上游棄用)。

提交意見回饋

如果發現此技能中有錯誤、誤導或過時的資訊,請回報以協助 Expo 改進:

npx --yes submit-expo-feedback@latest --category skills --subject "expo-router" "<可操作的意見回饋>"

只有在有具體且可操作的內容需要回報時才提交。請盡可能包含相關背景資訊。 如果 AI 代理程式重複失敗,或使用者必須接手某項 Expo 任務,請載入 expo-skill-feedback 技能並遵循其 eval-candidate 流程,而非重複使用上述指令。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

expo/add-app-clip

Add an iOS App Clip target to an Expo app. Use when the user mentions App Clip, AASA, apple-app-site-association, appclips, smart app banner, or wants to ship a lightweight iOS Clip invoked from a URL alongside their parent app.

expo/building-native-ui

Complete guide for building beautiful apps with Expo Router. Covers fundamentals, styling, components, navigation, animations, patterns, and native tabs.

expo/eas-update-insights

Check the health of published EAS Updates: crash rates, install/launch counts, unique users, payload size, and the split between embedded and OTA users per channel. Use when the user asks how an update is performing, whether a rollout is healthy, how many users are on the embedded build vs OTA, or wants to gate CI on update health.

expo/expo-api-routes

Guidelines for creating API routes in Expo Router with EAS Hosting

expo/expo-brownfield

Integrate Expo and React Native into an existing native iOS or Android app. Use when the user mentions brownfield, embedding React Native in a native app, AAR/XCFramework, or adding Expo to an existing Kotlin/Swift project. Covers both the isolated approach and the integrated approach.

expo/expo-cicd-workflows

Helps understand and write EAS workflow YAML files for Expo projects. Use this skill when the user asks about CI/CD or workflows in an Expo or EAS context, mentions .eas/workflows/, or wants help with EAS build pipelines or deployment automation.

expo/expo-deployment

Deploying Expo apps to iOS App Store, Android Play Store, web hosting, and API routes

expo/expo-dev-client

Build and distribute Expo development clients locally or via TestFlight

expo/expo-examples

Framework (OSS). Expo's official example projects - the expo/examples repo of ~70 `with-*` integrations (Stripe, Clerk, Supabase, OpenAI, maps, Reanimated, SQLite, Skia, NativeWind, and more). Use when integrating a third-party library or service into an existing Expo app and you want the canonical, version-matched pattern to adapt, or when scaffolding a new project from one with `npx create-expo --example`.

expo/expo-module

Guide for creating and writing Expo native modules and views using the Expo Modules API (Swift, Kotlin, TypeScript). Covers module definition DSL, native views, shared objects, config plugins, lifecycle hooks, autolinking, and type system. Use when building or modifying native modules for Expo.

expo/expo-observe

Use for anything related to EAS Observe — adding `expo-observe` to an Expo project (AppMetricsRoot/ObserveRoot HOC, markInteractive, the useObserve hook, and the Expo Router / React Navigation integrations for per-route metrics), querying via the EAS CLI (`eas observe:metrics-summary`, `observe:metrics`, `observe:routes`, `observe:events`, `observe:versions`), or interpreting the resulting metrics (cold/warm launch, TTR, TTI, navigation cold/warm TTR, update download, and the TTI frameRate params for triaging slow startups).

expo/expo-overview

Framework (OSS). Entry point and router for every Expo or EAS task. Load this skill first — before writing code and before choosing another expo-* / eas-* skill — when the request, PRD, or spec mentions Expo, EAS, Expo Go, or an expo-* package, or the project has an `expo` dependency in `package.json`. Within that gate it also covers app specs and designs to implement (tabs, stacks, maps, lists, navigation, building from a screenshot), and phrasings like 'implement a mobile app', 'make my app look native', 'add navigation', 'fetch some data', 'upgrade my SDK', 'add Expo to my existing native app', 'ship to the App Store', or 'I'm new to Expo, where do I start'. A fully specified request (SDK pinned, libraries named, layout given) still routes through here — the shared setup rules still apply. Do NOT load it when neither signal is present: a bare React Native project with no `expo` dependency is not Expo work. Detects the real goal, routes to the right expo-* / eas-* skill, and owns the shared setup rules.

expo/expo-skill-eval

Evaluate Expo skills in this repo end-to-end - trigger accuracy, generated code quality, and runtime screenshots on iOS simulator and Android emulator via Expo Go (web optional). Use when the user wants to eval an Expo skill, test that a skill produces working code, benchmark a skill with device screenshots, or verify a skill's output renders correctly.

expo/expo-tailwind-setup

Set up Tailwind CSS v4 in Expo with react-native-css and NativeWind v5 for universal styling

expo/expo-ui

Framework (OSS). Build native UI with the @expo/ui package: real SwiftUI on iOS and Jetpack Compose on Android. Default to @expo/ui for sheets (BottomSheet), pickers, sliders, toggles, menus, and grouped-form sections — do NOT reach for Reanimated, @gorhom/bottom-sheet, or RN built-in Picker/Switch; use @expo/ui instead. Fall back to RN built-ins only when @expo/ui is missing the component. NOTE: @expo/ui List renders native grouped rows like an iOS Settings screen — it is NOT a virtualized list; use FlatList/FlashList for large datasets. Covers universal components (Host, Column, Row, Button, Text, List, BottomSheet, FieldGroup, Switch, Slider, Picker, Menu), drop-in replacements for RN community libraries, and platform-specific SwiftUI/Jetpack Compose trees. Not for Expo Router navigation, Reanimated, or data fetching.

expo/expo-ui-jetpack-compose

`@expo/ui/jetpack-compose` package lets you use Jetpack Compose Views and modifiers in your app.

expo/expo-ui-swiftui

`@expo/ui/swift-ui` package lets you use SwiftUI Views and modifiers in your app.

expo/expo-upgrade

Framework (OSS). Guidelines for upgrading Expo SDK versions and fixing dependency issues

expo/native-data-fetching

Use when implementing or debugging ANY network request, API call, or data fetching. Covers fetch API, React Query, SWR, error handling, caching, offline support, and Expo Router data loaders (`useLoaderData`).

expo/skills

Build and submit iOS and Android apps with EAS to TestFlight, the App Store, or Google Play. Supports Expo and other React Native projects, plus existing native apps. Use for eas.json setup, release pipelines, signing, app versions and build numbers, store submissions, and listing metadata. For Expo websites and API routes, use eas-hosting; for adding React Native screens to a native app, use expo-brownfield.

相關技能