---
title: "How to build and submit a sitemap.xml for a React or Vite site"
description: "A React or Vite single page app ships with no sitemap.xml. How to build one at build time, submit it in Search Console, and read what Google says."
author: "Vimanyu Aggarwal"
date: "2026-12-01"
canonical: "https://vunora.ai/blog/sitemap-xml-react-vite"
---

# How to build and submit a sitemap.xml for a React or Vite site

![A vintage paper map of the Solent spread out on a table](https://vunora.ai/blog/sitemap-xml-react-vite.jpg)

You added ten pages to the site last month, and Google seems to know about three of them. On a React app built with Vite, there is often no sitemap.xml at all. If the coding tool wrote one, it wrote it once, by hand, so it lists the pages that existed that day.

The fix is a short step in your build that writes the file each time the site builds. This post shows that step for a Vite app, how to check the file, how to submit it in Search Console, and how to read the status Google gives back.

## What a sitemap lists

A [sitemap](https://vunora.ai/glossary/sitemap) is, in Google's words, "a file where you provide information about the pages, videos, and other files on your site." For most sites it is one XML file at `/sitemap.xml` with one entry per page.

This is the smallest one, from Google's own docs:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com/foo.html</loc>
    <lastmod>2022-06-04</lastmod>
  </url>
</urlset>
```

The sitemap protocol asks for a `<loc>` in each `<url>`, and says "All other tags are optional." Google adds its own rules:

- "Include the URLs in your sitemap that you want to see in Google's search results." That means the [canonical URL](https://vunora.ai/glossary/canonical-url) of each page, not a copy, a redirect or a page marked `noindex`.
- "Use fully-qualified, absolute URLs in your sitemaps." Write `https://www.example.com/pricing`, never `/pricing`.
- "Google ignores `<priority>` and `<changefreq>` values." It reads `<lastmod>` only when the date is "consistently and verifiably" accurate.
- One file holds at most 50,000 addresses or 50MB. Most vibe coded sites are far below that.

A sitemap is a list of suggestions, not an order. Google says it "doesn't guarantee that all the items in your sitemap will be crawled and indexed."

## Why a single page app has none

A React app made with Vite is a [client side rendering](https://vunora.ai/glossary/client-side-rendering) app: the server sends one `index.html`, and the browser builds each page from your code. Your routes live in that code, in the router. No file on the server lists them, and the Vite starter writes no sitemap.

What Vite does give you is the `public/` folder. Its docs say files there are "copied to the root of the dist directory as-is." So a `public/sitemap.xml` is served at `/sitemap.xml`. The job is to write that file before each build, from a list that stays current.

The list matters more on these apps. In [our study of vibe coded home pages](https://vunora.ai/research/crawler-first-read), 31% of the 517 we measured had a same-site link a crawler could follow on Google's first look. Once the code ran, 72% did. Google does run the code, but a sitemap hands it every address without waiting for that step.

On Lovable, check which generation you have. Lovable's docs say apps created from May 13, 2026 run on TanStack Start, and older React and Vite apps keep that stack unless the owner upgrades. They also say "Lovable creates a `robots.txt` with every new project, but not always a sitemap." The [Lovable SEO guide](https://vunora.ai/blog/lovable-seo) shows how to run Lovable's own SEO and AI search review.

The other two frameworks have their own way in. TanStack Start's SEO guide says it "can automatically generate a sitemap when you enable prerendering with link crawling," or you can write a server route at `src/routes/sitemap[.]xml.ts`. Next.js builds the file from `app/sitemap.ts`, which the [Next.js SEO checklist](https://vunora.ai/blog/nextjs-seo) covers.

## Generate it at build time on a Vite app

Three steps: list your pages, write the XML into `public/`, and run that before `vite build`.

**A sitemap.xml that stays current**

1. List every page you want in Google, by path
2. Write public/sitemap.xml from that list in a small Node script
3. Run the script before vite build in package.json
4. Add a Sitemap line to robots.txt

### 1 and 2. List the pages and write the file

```js
// scripts/sitemap.mjs
import { writeFileSync } from "node:fs"

const SITE = "https://www.example.com"

// Every page you want in Google, by path.
// Add posts or products from your data here too.
const paths = ["/", "/pricing", "/about", "/blog"]

const urls = paths
  .map((path) => `  <url>\n    <loc>${SITE}${path}</loc>\n  </url>`)
  .join("\n")

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls}
</urlset>
`

writeFileSync("public/sitemap.xml", xml)
console.log(`sitemap.xml lists ${paths.length} addresses`)
```

Keep the list to real pages. Leave out the not-found route, login screens, and any address that redirects. If your blog posts or products come from a database or a CMS, fetch that list in the script and add each address to `paths`.

Add `<lastmod>` only if you know the real date a page last changed. A date that is always today tells Google nothing, and Google says it uses the tag only when it is accurate.

### 3. Run it before the build

```json
{
  "scripts": {
    "build": "node scripts/sitemap.mjs && vite build"
  }
}
```

The script writes `public/sitemap.xml`, then Vite copies it into the build. Each deploy now carries a sitemap that matches the code it shipped. If your content changes without a code change, set your host to rebuild when it does.

### 4. Point robots.txt at it

Google lists a `Sitemap:` line in robots.txt as one way to tell it where the file is. Add this line, with your full address:

```text
Sitemap: https://www.example.com/sitemap.xml
```

[How to set up robots.txt on a vibe coded site](https://vunora.ai/blog/robots-txt-vibe-coded-site) shows the rest of that file.

**Prompt for Claude Code or Cursor**

```text
Add a sitemap.xml to this Vite and React app. Show me the plan first, and change nothing until I say yes.

1. Read the router and list every route. Mark which ones should be in Google and which should not, such as the not-found route, login, and any route that redirects.
2. For routes with a parameter, such as a blog post or a product, find where the list of items comes from.
3. Write scripts/sitemap.mjs. It builds one url entry per page with a full https address, and writes public/sitemap.xml. Leave out priority and changefreq.
4. Change the build script in package.json so the sitemap script runs before vite build.
5. Add a Sitemap line with the full address to public/robots.txt, and create that file if it is missing.

Then show me the sitemap the script writes for the current routes.
```

Paste it in your tool, opened in your site's repository.

## Check the file before you submit it

After the deploy, ask for the headers:

```bash
curl -I https://www.example.com/sitemap.xml
```

You want a `200` and a `content-type` with `xml` in it. If you see `text/html`, the file is missing. A single page app answers unknown addresses with its own page and a `200`, so the status alone fools you. The same trap catches robots.txt, and it is the reason behind a [soft 404 on a single page app](https://vunora.ai/blog/soft-404-single-page-app).

Then count the entries:

```bash
curl -s https://www.example.com/sitemap.xml | grep -c "<loc>"
```

The number should match the pages you meant to list. Open three or four of the addresses in a browser to make sure each one loads its own page.

## Submit it in Search Console

Google's help page for the Sitemaps report gives the steps. You need owner permission on the Search Console property.

1. Post the sitemap on your site.
2. Test that Google can reach it. The `curl` checks above are a quick first test.
3. Open the Sitemaps report in Search Console.
4. Paste the sitemap address into "Add a new sitemap" and choose Submit.

Google says "The sitemap should be fetched immediately." The report then shows one of three statuses:

**Sitemap statuses in Search Console**

|                | What Google says it means                                         | What to check                                                                                                      |
| -------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| Success        | The sitemap was loaded and processed successfully with no errors. | Nothing. Watch the Page indexing report over the next weeks.                                                       |
| Has errors     | The sitemap could be fetched, but has one or more errors.         | Open the row to see which entries failed, fix the script, and rebuild.                                             |
| Couldn't fetch | The sitemap could not be fetched for some reason.                 | The address, a robots.txt rule that blocks the file, and whether the address sends your app's page instead of XML. |

_Status text from Google's Sitemaps report help, read 1 December 2026._

Google lists the usual reasons for "Couldn't fetch." Among them: "The sitemap is blocked by your robots.txt file," "The URL provided for the sitemap is wrong," and "There is low crawl demand for the sitemap." When a fetch fails, Google "will retry for a few days, and then stop if the sitemap continues to be unavailable or has critical errors."

Keep your expectations right. Google says "submitting a sitemap is merely a hint." A listed page can still sit unindexed, and [crawled, currently not indexed](https://vunora.ai/blog/crawled-currently-not-indexed-vibe-coded-site) explains what to change when it does.

## How Vunora checks sitemap.xml

Vunora's [SEO checklist](https://vunora.ai/product/seo) has a check called "sitemap.xml lists every page." In the Monday run, and whenever someone chooses Run checklist, it reads your live sitemap. It reads `/sitemap.xml`, or the sitemaps your robots.txt names. Then it compares the addresses with every page you publish in Vunora.

**The sitemap check**

- Needs a fix: sitemap.xml lists every page (3 pages are missing from sitemap.xml., Fix sitemap.xml)

_The check name and message as Vunora shows them. The count is an example._

The messages say what it found. "No sitemap.xml on the live site." means the address sent no sitemap, including when it sent your app's page. "sitemap.xml lists all 12 pages." is a pass, with your own count. When some are missing, the card lists each page that is not in the file.

On a Vite or Next.js site, the failing card offers **Fix sitemap.xml**. On a Vite site, it adds `scripts/vunora-sitemap.mjs` and runs it before your build command, the same pattern as above. The script writes `public/sitemap.xml` at build time with every page and post you publish in Vunora, and it never fails the build. Where the site has a build hook set, Vunora rebuilds it when you publish, so the file stays current. On a Next.js site with the App Router, it adds `app/sitemap.ts`. If your site already has its own, Vunora leaves it alone and tells you to add your Vunora pages there.

The fix reaches your repository the way your site sends edits: a commit to your branch, or a pull request to review. The [checklist guide](https://vunora.ai/blog/check-every-page-against-the-seo-checklist) shows both messages.

## Where this stops

- Vunora does not submit your sitemap. The screen says so: "Vunora does not submit your sitemap to Google." You add it once in Search Console.
- The repository fix works on Next.js and Vite sites. On a TanStack Start site, you add the sitemap by hand.
- The Vite script lists the pages and posts you publish in Vunora. A route that lives only in your code, and not in Vunora, is not in that list.
- Vunora never hosts your site, and it does not change how your pages are built. It writes files to your repository, and your host deploys them.
- No sitemap makes Google index a page. It makes sure Google knows the address.

## Questions

### Does a small site need a sitemap?

Maybe not. Google says a site may not need one when it has "about 500 pages or fewer" and is "comprehensively linked internally." On a single page app, the links may not be in the HTML until the code runs, so a sitemap is a cheap way to hand Google every address.

### Should I set priority and changefreq?

No. Google's docs say it ignores both. Set `<lastmod>` only when you know the real date the page last changed.

### Where should sitemap.xml live?

At the root, as `/sitemap.xml`. Google says "a sitemap posted at the site root can affect all files on the site, which is where we recommend posting your sitemaps." On a Vite app, that means writing it into `public/`.

### Why does Search Console say "Couldn't fetch"?

Google could not get the file. Check the address you typed, check that robots.txt does not block it, and run `curl -I` to see whether the address sends XML or your app's page.

## Sources

- Google Search Central, sitemaps overview, read December 1, 2026: <https://developers.google.com/search/docs/crawling-indexing/sitemaps/overview>
- Google Search Central, build and submit a sitemap, read December 1, 2026: <https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap>
- Google Search Console Help, manage your sitemaps using the Sitemaps report, read December 1, 2026: <https://support.google.com/webmasters/answer/7451001>
- sitemaps.org, sitemaps XML format, read December 1, 2026: <https://www.sitemaps.org/protocol.html>
- Vite, static asset handling and the public directory, read December 1, 2026: <https://vite.dev/guide/assets>
- Next.js, sitemap.xml file convention, read December 1, 2026: <https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap>
- TanStack Start, SEO guide, read December 1, 2026: <https://tanstack.com/start/latest/docs/framework/react/guide/seo>
- Lovable, SEO and AI search, read December 1, 2026: <https://docs.lovable.dev/features/seo-aeo>
- Lovable, upgrade to TanStack Start, read December 1, 2026: <https://docs.lovable.dev/features/upgrade-to-tanstack-start>

_Drafted with AI help and checked against the product._
