首页指南参考教程

根布局

了解在使用 Expo Router 时如何使用根布局将全局提供程序添加到你的应用。


传统的 React Native 项目由单个根组件构成,该组件通常在 App.tsx 或 index.tsx 中定义。此模式通常用于将 Redux、主题、样式等全局提供程序注入到应用中,并延迟渲染,直到加载资源和字体。

¥Traditional React Native projects are structured with a single root component that is often defined in App.tsx or index.tsx. This pattern is often used to inject global providers such as Redux, Themes, Styles, and so on, into the app, and to delay rendering until assets and fonts are loaded.

在 Expo Router 中,你可以使用根布局(app/_layout.tsx)添加可通过应用中的任何路由访问的提供程序。

¥In Expo Router, you can use the Root Layout (app/_layout.tsx) to add providers which can be accessed by any route in the app.

尝试将提供商的范围缩小到仅需要它们的路由。这将提高性能并减少重新渲染。

¥Try to reduce the scope of your providers to only the routes that need them. This will improve performance and cause fewer rerenders.