Skip to content
雲里
里雾

Expo Router 目录路由命名规则

mindgym 开发 更新于 2026/4/23

Expo Router 中,普通目录下的 index.tsx 的路由名称是 目录名/index,不是 目录名。只有用 (括号) 包裹的 group 目录才会做名称折叠。搞混这两者会导致 No route named "xxx" 警告。


规则

文件路径路由名称URL 路径
app/index.tsxindex/
app/(tabs)/index.tsxindex/
app/(tabs)/history/index.tsxhistory/index/history
app/(tabs)/settings/index.tsxsettings/index/settings
app/train/[module].tsx[module]/train/schulte

关键区别:

MindGym 中的实际 bug

Tab layout 中配置 Tab.Screen 时,错误地用了 name="history"

// ❌ 报警告: No route named "history"
<Tabs.Screen name="history" />

// ✅ 正确
<Tabs.Screen name="history/index" />

Expo Router 内部按文件路径注册路由,history/index.tsx 注册的名字就是 "history/index",用 "history" 找不到。

为什么用目录而不是扁平文件

history/index.tsx 而非 history.tsx 的好处是预留了二级页面扩展点——后续可以直接添加 history/[id].tsx(记录详情页),不需要重构目录结构。

参见

参考