<!-- Generated from zh/llms-txt-remix/index.html. The canonical document is the HTML page. -->

- [ 首页 ](/zh/) 
/
- [ 如何创建 ](/zh/how-to-create/) 
/
- Remix 指南            
# Remix 的 `llms.txt`

Remix 和 React Router 有两种方法：在 public/ 中放置一个零配置静态文件，或创建返回纯文本 Response 的资源路由，也可选择根据你的内容生成。

最近更新: 2026年10月29日

本页内容

- [ Remix v2、React Router 与 Remix 3 ](#versions)
- [ public/ 中的选项 1：静态文件 ](#static)
- [ 选项 2：资源路由 ](#resource-route)
- [ 现有的 Remix v2 应用 ](#remix-v2)
- [ 验证 ](#verify)             
## Remix v2、React Router 与 Remix 3

React Router 文档将 React Router v7 描述为 Remix 在 v2 之后的下一个主要版本，因此基于 Remix v2
构建的应用会以 React Router 框架模式应用的形式延续。当前的主要版本是 React Router 8（`react-router` 8.0.0 发布于 2026 年 6 月 17 日；撰写本文时最新版本为 8.5.1）。另外，`remix` npm 包现在发布的是
Remix 3（3.0.0 发布于 2026 年 10 月 1 日），这是一个拥有自己 API 的不同框架，本指南不涉及。

以下示例面向 **React Router 框架模式**。另有一个简短的章节介绍
[现有的 Remix v2 应用](#remix-v2)。

备注

应使用哪种方案？

使用  静态文件  ，如果您的  llms.txt  很少变化，而且无需根据内容生成。请使用
资源路由  
用于动态生成，尤其当你的文档存储在数据库中或由 MDX 文件生成时。

## public/ 中的选项 1：静态文件

React Router 框架模式使用 Vite 构建。Vite 会将 `public/`
目录中的文件原样复制到构建输出的根目录，因此只要该输出作为静态资源提供，`public/llms.txt`
就会在 `/llms.txt` 提供。无需路由配置。
public/llms.txt, directory structure    复制     

```
# Static file approach (React Router framework mode, Vite-based)
#
# Place your file at: public/llms.txt
# Vite copies public/ to the root of the build output as-is.
#
# Project structure:
# your-app/
# ├── public/
# │   └── llms.txt   ← add this
# ├── app/
# └── vite.config.ts

```

每个路径只使用一种方案：不要同时发布 `public/llms.txt` 和针对 `/llms.txt`
的资源路由。

## 选项 2：资源路由

在 React Router 中，当路由模块导出 `loader`（或 `action`）且没有默认组件时，该路由就成为资源路由。在
`app/routes.ts` 中声明该路由，然后导出一个 `loader`，返回设置了正确
`Content-Type` 的 `Response`。loader 参数类型来自生成的
`./+types/ ` 模块。
app/routes.ts    复制     

```
// app/routes.ts
import { type RouteConfig, route } from '@react-router/dev/routes';

export default [
// ...your other routes
route('llms.txt', 'routes/llms-txt.ts'),
] satisfies RouteConfig;

```
app/routes/llms-txt.ts    复制     

```
// app/routes/llms-txt.ts
// Resource route: it exports a loader and no default component.
// Served at /llms.txt via route('llms.txt', 'routes/llms-txt.ts') in app/routes.ts
import type { Route } from './+types/llms-txt';

export async function loader(_: Route.LoaderArgs) {
const content = `# Your Site

> One-sentence description of what your site or product does.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog.

## Product

- [Overview](https://yoursite.com/product): Features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
`;

return new Response(content, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}

```

如果你的应用通过 `@react-router/fs-routes` 使用基于文件的路由，`[.]`
转义仍会将名为 `llms[.]txt.ts` 的文件映射到 `/llms.txt`：
app/routes.ts, flatRoutes() alternative    复制     

```
// app/routes.ts, file-based alternative
import { type RouteConfig } from '@react-router/dev/routes';
import { flatRoutes } from '@react-router/fs-routes';

export default flatRoutes() satisfies RouteConfig;

// With flatRoutes(), name the module app/routes/llms[.]txt.ts:
// the [.] escapes the dot, so the URL is /llms.txt

```

示例

返回 text/plain 的 Response

对于在 UI 之外使用的资源路由，React Router 文档建议返回  Response 
实例，以使编码保持明确。 Response.json()  等 JSON 辅助函数会设置 JSON 内容类型；对于
llms.txt ，请使用  new Response(body, { headers: { 'Content-Type': 'text/plain;
charset=utf-8' } }) 。

若要从内容层动态生成，请在加载器中获取文档，并以编程方式构建 Markdown 链接列表：
app/routes/llms-txt.ts, dynamic    复制     

```
// app/routes/llms-txt.ts
// Generate from your content / MDX files
import type { Route } from './+types/llms-txt';
// Your own data access module (example name)
import { getAllDocs } from '../models/docs.server';

export async function loader(_: Route.LoaderArgs) {
// Fetch your documentation index from a DB or file system
const docs = await getAllDocs();

const links = docs
.map((doc) => `- [${doc.title}](https://yoursite.com/docs/${doc.slug}/): ${doc.summary}`)
.join('\n');

const body = [
'# Your Site',
'',
'> One-sentence summary of your project.',
'',
'## Documentation',
'',
links,
].join('\n');

return new Response(body, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}

```

## 现有的 Remix v2 应用

如果你尚未迁移，同样的思路也适用于采用扁平路由约定的 Remix v2：在
`app/routes/llms[.]txt.ts` 放置一个模块，其 `loader` 返回纯文本
`Response`。类型来自你的适配器包（`@remix-run/node`、
`@remix-run/cloudflare` 或 `@remix-run/deno`）。对于新项目，React Router
的 [升级指南](https://reactrouter.com/7.18.5/upgrading/remix) 介绍了迁移路径。
app/routes/llms[.]txt.ts, Remix v2    复制     

```
// app/routes/llms[.]txt.ts  (Remix v2 only)
// v2 flat route convention: [.] escapes the dot, URL is /llms.txt
import type { LoaderFunctionArgs } from '@remix-run/node'; // or cloudflare/deno

export async function loader(_: LoaderFunctionArgs) {
return new Response('# Your Site\n\n> One-sentence summary.\n', {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}

```

## 验证

部署后，确认文件已正确提供：
Verification    复制     

```
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8

curl https://yoursite.com/llms.txt | head -5
```

## 相关指南

- [如何创建 llms.txt](/zh/how-to-create/)、模板和检查清单。 
- [llms.txt 格式参考](/zh/llms-txt-format/)，规范细节。 
- [Vercel 指南](/zh/llms-txt-vercel/)，部署和缓存头。 
- [Cloudflare Pages 指南](/zh/llms-txt-cloudflare/)，CDN 配置。 
- [验证器](/zh/validator/) · [生成器](/zh/generator/).         
## 来源

- [ llmstxt.org，社区提案 ](https://llmstxt.org/)
- [ React Router，从 Remix v2 升级 ](https://reactrouter.com/7.18.5/upgrading/remix)
- [ React Router，资源路由 ](https://reactrouter.com/how-to/resource-routes)
- [ React Router，routes.ts ](https://reactrouter.com/api/framework-conventions/routes.ts)
- [ React Router，文件路由约定 ](https://reactrouter.com/how-to/file-route-conventions)
- [ Vite，public 目录 ](https://vite.dev/guide/assets)
- [ Remix（remix.run），当前框架网站 ](https://remix.run/)
- [ Remix v2 文档，资源路由 ](https://v2.remix.run/docs/guides/resource-routes/)
