# Add a Sitemap to a React Router App

Yes. An agent adds sitemap.xml and robots.txt resource routes to a React Router app, lists the URLs from the route config, checks the built server and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-sitemap/react-router/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the app is built and served before it adds a route. In an app shaped like the `default` template in remix-run/react-router-templates, `package.json` has `react-router build`, `react-router dev`, `react-router-serve ./build/server/index.js` and a `typecheck` script that runs `react-router typegen` then `tsc`, with `react-router`, `@react-router/node` and `@react-router/serve` on the latest line and Vite 8 with the Tailwind plugin in `vite.config.ts`. `react-router.config.ts` sets `ssr: true`, `app/routes.ts` registers a single `index("routes/home.tsx")`, `app/root.tsx` renders the `Layout` with `Meta`, `Links` and `Scripts`, and `app/routes/home.tsx` exports `meta()` for the title and description. `public/` holds only `favicon.ico`, so there is no `robots.txt` either, and nothing tells a crawler which URLs exist.

It adds two resource routes, which in framework mode are route modules that export a `loader` and no component: `app/routes/sitemap[.]xml.ts` and `app/routes/robots[.]txt.ts`, the brackets escaping the dot in the file name, registered in `app/routes.ts` with `route("sitemap.xml", ...)` and `route("robots.txt", ...)`. The sitemap loader returns a `Response` with `Content-Type: application/xml` and a `Cache-Control` header, listing one `<url>` per public path with `<loc>` built from a `SITE_URL` environment variable and falling back to the request's origin when it is unset. The paths come from a new `app/sitemap.ts` that exports the static paths and a function for dynamic ones, with a comment showing where to append entries from a database or CMS; for this template the list is `/`. The robots loader returns `User-agent: *`, `Allow: /` and a `Sitemap:` line pointing at the sitemap URL.

The template has no test runner of its own; the repository tests templates from the `.tests` directory with Playwright, by building each template and starting it. The agent follows that: it runs `npm run typecheck`, which regenerates the `+types` for the two new routes, then `npm run build` and `npm run start`, and reads both URLs with `curl -i` to check the status, the content type and the XML. It also opens the sitemap in the sandbox browser to confirm the server renders it as XML rather than as the app shell.

Nothing in `root.tsx` or the home route changes. The `meta()` export stays where it is, and the pull request notes that pages added later only need their path appended in `app/sitemap.ts`, or their ids returned from the dynamic function.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "codex",
  "input": "Add a sitemap and robots.txt to this React Router app and open a pull request. Read package.json, react-router.config.ts, vite.config.ts, app/routes.ts, app/root.tsx, app/routes/home.tsx and the public directory first. Add resource routes app/routes/sitemap[.]xml.ts and app/routes/robots[.]txt.ts, each exporting only a loader, and register them in app/routes.ts as sitemap.xml and robots.txt. Build the sitemap's loc values from a SITE_URL environment variable, falling back to the request origin, over a list of public paths exported from a new app/sitemap.ts with a function for dynamic entries. Return application/xml with a Cache-Control header for the sitemap and text/plain for robots.txt, which must include a Sitemap line. Run npm run typecheck, npm run build and npm run start, fetch both URLs with curl -i and paste the responses in the pull request. Do not change root.tsx or the home route.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with two new route modules, one new `app/sitemap.ts`, and two lines in `app/routes.ts`. The description shows the `curl -i` output for `/sitemap.xml` with its `application/xml` content type and the `<urlset>` body, and for `/robots.txt` with the `Sitemap:` line, plus the `typecheck` result.

The template ships no GitHub Actions workflow of its own, so the typecheck and the responses in the description are the proof, with the full build and start commands in the run's transcript. A reviewer who runs the repository's Playwright suite from `.tests` sees it still start the template as before.

A reviewer checks that `SITE_URL` is set in the deployment so the `<loc>` values are absolute and canonical, that the dynamic function is wired to the real data source when there is one, and that the sitemap route is excluded from any auth middleware added later. Then they submit the URL in Search Console.

## Run it on every new site launched

An agency that starts each client site from the same React Router template sends one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`. Each run reads that app's `routes.ts`, so a site with a blog gets its post slugs listed from the loader's data source, and each opens its own pull request.

With a `webhook_url` on the key, `run.completed` arrives per run with the `session_url`, and a handler can mark the launch checklist item done once the pull request merges.

## Why run it on Rush?

A sitemap route is small, but whether the server returns XML or the HTML shell depends on the route being a true resource route with no default export and the file name escaping the dot, and the only honest check is to build and request it. In a Rush sandbox the agent builds the app, starts the production server and reads the real response, and that `curl` output is kept in the run with the pull request.

The same request runs on every site built from the template without a local checkout, and the sandbox parks after the turn, so a follow-up to add `<lastmod>` from the CMS wakes it where it stopped.

## Frequently asked questions

### Why not generate a static sitemap.xml at build time?

A loader can list dynamic pages from the same data the app serves, and it needs no extra build step. For a fully static site, `react-router.config.ts` can prerender routes, and the pull request notes that as the alternative.

### Where does the site URL come from?

From a `SITE_URL` environment variable read in the loader, with the request origin as the fallback for local runs. Set it in the deployment so the `<loc>` values match the canonical host.

### Will the sitemap route render the app shell?

No. A route module that exports a `loader` and no component is a resource route, and React Router returns the loader's `Response` as is. The `curl -i` output in the pull request shows the `application/xml` content type to prove it.

### How do I add dynamic pages later?

Return their paths from the function in `app/sitemap.ts`, which the loader awaits before it writes the XML. A blog would query its posts there and return one path per slug.

## More React Router jobs

- [Add Structured Logging to a React Router App With a Custom Express Server](https://getrush.ai/run/add-structured-logging/react-router/)
- [Fix "'Switch' is not exported from 'react-router-dom'" after upgrading to React Router 6](https://getrush.ai/run/fix-switch-is-not-exported-from-react-router-dom/react-router/)
- [Turn a Labeled GitHub Issue Into a Pull Request on a React Router App](https://getrush.ai/run/github-issue-to-pr/react-router/)

## The same job on other stacks

- [Add a Sitemap to a Sphinx Docs Site](https://getrush.ai/run/add-sitemap/sphinx/)
- [Add a Sitemap to a SvelteKit App](https://getrush.ai/run/add-sitemap/sveltekit/)
- [Add an XML Sitemap to a Symfony App](https://getrush.ai/run/add-sitemap/symfony/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
