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 设置堆栈的默认屏幕,并且应与有效的文件名匹配(不包含扩展名)。

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 或重新加载页面时,仍然会显示返回箭头。

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

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

anchor 仅在深度链接到某个路由时使用。在应用内导航期间,你要导航到的路由将成为锚点路由。若要同时在目标路由下方加载锚点路由,请在 <Link /> 组件上使用 withAnchor 属性。命令式 API 接受相同的选项。

// 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