This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 路由 UI

用于 React Native 和 Web 应用的基于文件的路由库。

Android
iOS
tvOS
Web
Included in Expo Go
Recommended version:
~58.0.17

expo-router 是一个用于 React Native 和 Web 应用的路由库。它通过基于文件的路由系统实现导航管理,并提供原生导航组件。

Expo Router 指南

了解 Expo Router 的基础知识、导航模式、核心概念等。

安装

🌐 Installation

要在你的项目中使用 Expo Router,你需要进行安装。请按照 Expo Router 安装指南中的说明操作:

🌐 To use Expo Router in your project, you need to install. Follow the instructions from the Expo Router's installation guide:

安装 Expo 路由

了解如何在项目中安装 Expo Router。

应用配置中的配置

🌐 Configuration in app config

如果你使用 default 模板创建新项目,expo-router 的 配置插件 已经在你的应用配置中设置好了。

🌐 If you are using the default template to create a new project, expo-router's config plugin is already configured in your app config.

Example app.json with config plugin

app.json
{ "expo": { "plugins": ["expo-router"] } }

Configurable properties

NameDefaultDescription
root"app"

Changes the routes directory from app to another value. Avoid using this property unless you have a specific need.

originundefined

Production origin URL where assets in the public folder are hosted. The fetch function is polyfilled to support relative requests from this origin in production. The development origin is inferred using the Expo CLI development server.

headOriginundefined

A more specific origin URL used in the expo-router/head module for iOS handoff. Defaults to origin.

asyncRoutes{ web: true }

Enable async routes (lazy loading). Stable and enabled by default on web in SDK 58 and later. Experimental and disabled by default on native. Can be an AsyncRouteOption or an object with platform-specific AsyncRouteOption values ({ android, ios, web, default }). Explicit platform values take precedence over default. Production async routes are web-only.

platformRoutestrue

Enable or disable platform-specific routes (for example, index.android.tsx and index.ios.tsx).

sitemaptrue

Enable or disable the automatically generated sitemap at /_sitemap.

partialRouteTypestrue

Enable partial typed routes generation. This allows TypeScript to provide type checking for routes without requiring all routes to be statically known.

redirectsundefined

An array of static redirect rules. Each rule is a RedirectConfig with source, destination, and optionally permanent (defaults to false) and methods (HTTP methods to redirect).

rewritesundefined

An array of static rewrite rules. Each rule is a RewriteConfig with source, destination, and optionally methods (HTTP methods to rewrite).

headersundefined

A list of headers that are set on every route response from the server. The value can be a string or an array of strings.

pageHeadersundefined

An array of header rules that are set on a specific page's response from the server. Each rule is a PageHeadersConfig with source and headers. Rules only apply to page responses, not API routes or data loaders.

disableSynchronousScreensUpdatesfalse

Disable synchronous layout updates for native screens. This can help with performance in some cases.

unstable_useServerMiddlewarefalse
Deprecated

No longer required as of SDK 58 and has no effect. Remove this option from your app config.

unstable_useServerDataLoadersfalse
Deprecated

No longer required as of SDK 58 and has no effect. Remove this option from your app config.

unstable_useServerRenderingfalse
Deprecated

No longer required as of SDK 58 and has no effect. Remove this option from your app config.

apiRoutesDepends on web.output

Enable API routes with static or server output. Defaults to true for server output and false for static output.

用法

🌐 Usage

有关核心概念、符号模式、导航布局和常见导航模式的信息,请从“路由 101”部分开始:

🌐 For information core concepts, notation patterns, navigation layouts, and common navigation patterns, start with Router 101 section:

路由入门

应用接口

🌐 APIs

API描述
Stack栈导航器、工具栏和屏幕组件
Link链接和重定向组件
Color平台颜色工具
Native Tabs原生选项卡导航
Split View分屏视图布局
UI无头选项卡组件

应用接口

🌐 API

import { useRouter, Tabs, Navigator, Slot } from 'expo-router';

No API data file found, sorry!