All jobs

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 RushOpens 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 with this body:

{
  "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.

The use case this job follows, with its automation and trigger: Hand off a long task.

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

The same job on other stacks

Keep reading