This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
路由设置
编辑页面
了解如何在 Expo Router 中使用静态属性配置布局。
initialRouteName
当深度链接到某个路由时,你可能希望为用户提供一个“返回”按钮。initialRouteName 用于设置栈的默认屏幕,并且应与一个有效的文件名匹配(不含扩展名)。
srcapp_layout.tsxindex.tsxother.tsxsrc/app/_layout.tsx
import { Stack } from 'expo-router'; export const unstable_settings = { // 确保任何路由都可以链接回 `/` initialRouteName: 'index', }; export default function Layout() { return <Stack />; }
现在,直接深度链接到 /other 或重新加载页面时,仍然会显示返回箭头。
当使用 array syntax (foo,bar) 时,你可以在 unstable_settings 对象中指定某个分组的名称,以定位到特定的片段。
other.tsx
export const unstable_settings = { // 用于 `(foo)` initialRouteName: 'first', // 用于 `(bar)` bar: { initialRouteName: 'second', }, };
initialRouteName 仅在深度链接到某个路由时使用。在应用导航过程中,你正在前往的路由将成为初始路由。你可以通过在 <Link /> 组件上使用 initial 属性,或通过在命令式 API 中传入该选项来禁用此行为。
// 如果这会导航到一个新的 _layout,不要覆盖初始路由 <Link href="/route" initial={false} />; router.push('/route', { overrideInitialScreen: false });