Proper Meta Tags
Add a title, description, and Open Graph tags on every page.
SEO (Search Engine Optimization) in React needs some extra attention. This is especially true for SPA apps (Single Page Applications), because in these apps, the content usually shows up only after JavaScript finishes loading.
In most client-rendered SPAs, the first HTML page that loads is almost empty. The actual content appears only after the JavaScript runs and React builds the page.
How this affects SEO:
Proper Meta Tags
Add a title, description, and Open Graph tags on every page.
Server-Side Rendering
SSR using frameworks like Next.js or Remix sends ready-made HTML to search engines.
Pre-rendering
Create static HTML versions of your pages so they are easier to crawl.
Clean URLs
Use simple, readable URLs like /user/123 instead of long URLs full of query parameters.
Fast Performance
Use lazy loading, code splitting, and optimized images to keep your site fast.
For meta tags, use the library that is still maintained: react-helmet-async.
Why not the old react-helmet?
Install it:
npm install react-helmet-asyncWrap your app with it:
import { HelmetProvider } from "react-helmet-async";
function App() { return ( <HelmetProvider> <Main /> </HelmetProvider> );}import { Helmet } from "react-helmet-async";
function Home() { return ( <> <Helmet> <title>Home Page</title> <meta name="description" content="This is home page" /> </Helmet>
<h1>Home</h1> </> );}function User({ user }) { return ( <> <Helmet> <title>{user.name}</title> <meta name="description" content={user.bio} /> </Helmet>
<h1>{user.name}</h1> </> );}<Helmet> <meta property="og:title" content="My App" /> <meta property="og:description" content="Best app" /> <meta property="og:image" content="/image.png" /></Helmet>A sitemap is simply a list of your website’s important URLs. It helps search engines crawl your site faster and more easily.
Example sitemap.xml:
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://example.com/</loc> </url> <url> <loc>https://example.com/about</loc> </url></urlset>Install:
npm install react-router-sitemapExample:
const Sitemap = require("react-router-sitemap").default;
function generateSitemap() { return new Sitemap(router).build("https://example.com").save("./public/sitemap.xml");}
generateSitemap();Install:
npm install sitemapExample script:
const { SitemapStream, streamToPromise } = require("sitemap");const fs = require("fs");
const sitemap = new SitemapStream({ hostname: "https://example.com" });
sitemap.write({ url: "/", changefreq: "daily", priority: 1.0 });sitemap.write({ url: "/about", changefreq: "monthly", priority: 0.7 });
sitemap.end();
streamToPromise(sitemap).then((data) => { fs.writeFileSync("./public/sitemap.xml", data.toString());});Example of dynamic routes:
/users/1/users/2/users/3const users = [1, 2, 3];
users.forEach((id) => { sitemap.write({ url: `/user/${id}`, changefreq: "weekly", priority: 0.8, });});User-agent: *Allow: /
Sitemap: https://example.com/sitemap.xmlEven if you use Helmet properly, a pure SPA still has limits when it comes to SEO.
The best way to get strong SEO is: