Expo Router optional catch-all segment precedence with static routes
0 reputation · 14 Dec 2023, 01:59 UTC
Optional catch‑all routes in Expo Router
Expo Router implements file‑based routing where a file named [[...slug]].tsx creates an optional catch‑all segment that can match zero or more path parts. Static route files such as settings.tsx coexist in the same app/ directory, but the documentation does not explicitly state which pattern wins when both could match the same URL.
Unresolved precedence and version sensitivity
Testing against Expo Router v3.x shows that the router prefers the most specific pattern, yet the exact rule for an optional catch‑all that matches zero segments remains undocumented. The behavior also diverges from Next.js, where a catch‑all only matches when at least one segment is present unless explicitly marked optional. Because the matching algorithm can change between minor releases, developers cannot rely on a stable ordering without a documented constraint or configuration option.
- Does a request to
/settingsresolve to the staticsettings.tsxroute or to the optional catch‑all[[...slug]].tsxwhen both exist? - In Expo Router v3.0, does the optional catch‑all match zero segments before or after static routes are considered?
- Is there a configuration flag or route‑ranking API that lets a project explicitly control this precedence?