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 中使用静态属性配置布局。


anchor

在深度链接到某个路由时,你可能想给用户提供一个“返回”按钮。anchor 设置堆栈的默认屏幕,并且应该匹配一个有效的文件名(不带扩展名)。

🌐 When deep linking to a route, you may want to provide a user with a "back" button. The anchor sets the default screen of the stack and should match a valid filename (without the extension).

src
 app
  _layout.tsx
  index.tsx
  other.tsx
src/app/_layout.tsx
import { Stack } from 'expo-router'; export const unstable_settings = { // Ensure any route can link back to `/` anchor: 'index', }; export default function Layout() { return <Stack />; }

现在直接深度链接到 /other 或重新加载页面时,仍然会显示返回箭头。

🌐 Now deep linking directly to /other or reloading the page will continue to show the back arrow.

使用array syntax (foo,bar) 时,你可以在 unstable_settings 对象中指定一个组的名称,以定位特定的段。

🌐 When using array syntax (foo,bar) you can specify the name of a group in the unstable_settings object to target a particular segment.

other.tsx
export const unstable_settings = { // Used for `(foo)` anchor: 'first', // Used for `(bar)` bar: { anchor: 'second', }, };

anchor 仅在深度链接到某个路由时使用。在应用导航期间,你要导航的路由将是锚点路由。如果你还想在目标路由下加载锚点路由,可以在 <Link /> 组件上使用 withAnchor 属性。命令式 API 也接受相同的选项。

🌐 The anchor is only used when deep-linking to a route. During app navigation, the route you are navigating to will be the anchor route. To also load the anchor route below the target route, use the withAnchor prop on the <Link /> component. The imperative APIs accept the same option.

// If this navigates to a new _layout, load the anchor route below the target route <Link href="/route" withAnchor />; router.push('/route', { withAnchor: true });

initialRouteName