保留路径

由 Metro 和 Expo Router 保留的 URL 路径,你应该避免将其用于路由或静态文件。


如果你创建一个路由或在某些 URL 路径下放置静态文件,Metro 或 Expo Router 将拦截请求,而不是提供你的内容。根据路径的不同,这可能会导致“404 未找到资源”错误,或者你的页面被内部开发服务器响应悄悄替换。

🌐 If you create a route or place static files at certain URL paths, Metro or Expo Router will intercept the request instead of serving your content. Depending on the path, this can result in a "404 Asset not found" error or your page being silently replaced by an internal dev server response.

/assets/*

Metro 在此路径提供所有打包的资源(图片、字体和其他文件)。如果你在 app/assets.tsx 创建一个路由或在 public/assets/ 创建一个目录,Metro 会拦截请求,你的内容将永远无法被访问。

🌐 Metro serves all bundled assets (images, fonts, and other files) at this path. If you create a route at app/assets.tsx or a directory at public/assets/, Metro intercepts the request and your content is never reached.

这适用于顶层路由和静态文件:

🌐 This applies to both top-level routes and static files:

app
assets.tsxConflicts with Metro
assets
  index.tsxConflicts with Metro
public
assets
  logo.pngConflicts with Metro

重命名你的路由或目录以避免冲突:

🌐 Rename your route or directory to avoid the conflict:

app
media.tsxWorks
public
images
  logo.pngWorks

/_expo/*

Expo Router 使用此路径用于多个内部中间件,包括开发工具和清单。请勿在此路径下创建路由或静态文件。

🌐 Expo Router uses this path for multiple internal middlewares, including dev tools and manifests. Do not create routes or static files under this path.

/_flight/*

React 服务器组件在内部使用此路径。请不要在此路径下创建路由或静态文件。

🌐 React Server Components use this path internally. Do not create routes or static files under this path.

/inspector

React Native 使用 /inspector/debug/inspector/network 作为调试器。避免创建与 /inspector 或其子路径匹配的路由。

🌐 React Native uses /inspector/debug and /inspector/network for the debugger. Avoid creating routes that match /inspector or its sub-paths.

/expo-dev-plugins/*

Expo 开发工具插件使用此路径。不要在此路径下创建路由或静态文件。

🌐 Expo development tool plugins use this path. Do not create routes or static files under this path.

/manifest

开发服务器在此路径提供本地应用清单。如果你在 app/manifest.tsx 创建一个路由,开发服务器将返回清单 JSON 而不是你的页面。你的路由在开发过程中似乎会静默地无法加载。

🌐 The dev server serves the native app manifest at this path. If you create a route at app/manifest.tsx, the dev server responds with manifest JSON instead of your page. Your route will appear to silently not load during development.

/_sitemap

Expo Router 会在此路径下自动生成一个 sitemap 路由以进行调试。如果你在 app/_sitemap.tsx 创建一个路由,它将覆盖内置的 sitemap。有关注此功能的更多详情,请参见 Sitemap

🌐 Expo Router automatically generates a sitemap route at this path for debugging. If you create a route at app/_sitemap.tsx, it will override the built-in sitemap. See Sitemap for more details on this feature.

/public/*

如果你的项目有一个 public 目录,/public URL 路径可能会与静态文件服务冲突。避免在 app/public.tsxapp/public/index.tsx 创建路由,因为当 public 目录存在时,该路径会被隐式保留。

🌐 If your project has a public directory, the /public URL path may conflict with static file serving. Avoid creating a route at app/public.tsx or app/public/index.tsx since the path is implicitly reserved when the public directory exists.

/favicon.ico

与上述路径不同,/favicon.ico 可以安全覆盖。当没有提供图标时,Expo CLI 会提供默认的 favicon。你可以通过在 public 目录中放置 favicon.ico 文件或创建一个 API 路由 来替换它。

🌐 Unlike the paths above, /favicon.ico is safe to override. Expo CLI serves a default favicon when none is provided. You can replace it by placing a favicon.ico file in your public directory or by creating an API route.