SEO Basics in TanStack Start: Meta Tags, robots.txt and a Dynamic Sitemap
Prefer to watch? Here is the video version of this tutorial: What is SEO? SEO stands for Search Engine Optimization. It is the practice of improving a website so it ranks higher in unpaid ("organic") search results on engines like Google. When people search for a product, service or answer online, SEO helps search engines understand what your website is about and recommend it to the right…
To improve search engine optimization (SEO) on a website, start by adding basic elements like page titles, descriptions, a robots.txt file, and a sitemap. In a TanStack Start demo store, open the About page and add a head section to the route. The head section contains meta tags, such as the page title and description, which are displayed in the browser tab, bookmarks, and Google search results.
Create a file named seo.ts at src/lib/seo.ts and include a reusable function called seo. This function takes in parameters for the page title, description, image, and path, and generates the necessary meta tags and Open Graph tags. The seo function formats titles consistently, handles standard tags, prepares social previews, and only adds what is provided, ensuring clean and error-free meta tags.
To use the seo function, import it from the seo.ts file and apply it to the About page's head section. The seo function will generate the appropriate meta tags based on the provided parameters, such as the page title, description, and path. Additionally, create a robots.txt file at the root of your domain, which instructs search engine bots on which pages or sections to crawl and which to skip. This helps keep bots out of private or irrelevant pages and optimizes crawl budget.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.