If you build sites for local service businesses, sooner or later someone asks for city pages. A plumbing company serves twelve suburbs, a law firm takes clients across three counties, an HVAC contractor wants to show up for "AC repair" in every town on its route. The obvious engineering answer is a dynamic route, a list of cities and a template. The obvious SEO risk is that you ship forty near-identical pages that search engines treat as thin or duplicate content and quietly ignore.
This post covers how to build location pages in the Next.js App Router so they are fast, crawlable and genuinely different from each other. The code is simple. The harder part is the data model, because the data is what makes each page worth indexing.
Start with the data, not the template
Most thin location pages come from a template that swaps one word. "We offer plumbing in {city}" repeated forty times is not forty pages of content, it is one page with a find and replace.
Before writing any routes, define what actually differs between locations. For a real service business, that usually includes:
- The neighborhoods or zip codes actually served from that area
- Which services are offered there (not every crew covers every service everywhere)
- Typical response time or scheduling notes for that area
- Local conditions that change the work, such as older housing stock, hard water, climate or permit rules
- Projects or job types that are common in that area
- Answers to questions customers in that area actually ask
If you cannot fill those fields with something true for a city, that city probably should not have its own page yet. That rule alone prevents most thin content.
Here is a typed shape for that data:
// lib/locations.ts export type Location = { slug: string; city: string; region: string; areasServed: string[]; services: string[]; intro: string; localNotes: string[]; faqs: { q: string; a: string }[]; indexable: boolean; }; export const locations: Location[] = [ { slug: "houston", city: "Houston", region: "TX", areasServed: ["Heights", "Montrose", "Bellaire", "Spring Branch"], services: ["website-design", "local-seo", "google-ads"], intro: "Written specifically for this market, not generated.", localNotes: ["Notes that only make sense for this city."], faqs: [{ q: "A real local question", a: "A real answer." }], indexable: true, }, ]; export function getLocation(slug: string) { return locations.find((l) => l.slug === slug); } The indexable flag matters. It lets you keep a draft location in the data without exposing it to search engines until it has real content.
Whether this lives in a TypeScript file, a CMS or a database does not change the approach. A typed file is fine for a few dozen locations and keeps everything in version control.
The dynamic route
With the App Router, one folder handles every location:
app/ locations/ page.tsx [slug]/ page.tsx Generate the static paths at build time so every page is pre-rendered HTML:
// app/locations/[slug]/page.tsx import { notFound } from "next/navigation"; import { locations, getLocation } from "@/lib/locations"; export const dynamicParams = false; export function generateStaticParams() { return locations.map((l) => ({ slug: l.slug })); } export default async function LocationPage({ params, }: { params: Promise<{ slug: string }>; }) { const { slug } = await params; const loc = getLocation(slug); if (!loc) notFound(); return ( <main> <h1>Web Design and Local SEO in {loc.city}, {loc.region}</h1> <p>{loc.intro}</p> <section> <h2>Areas we serve around {loc.city}</h2> <ul> {loc.areasServed.map((a) => ( <li key={a}>{a}</li> ))} </ul> </section> <section> <h2>What is different about {loc.city}</h2> {loc.localNotes.map((n, i) => ( <p key={i}>{n}</p> ))} </section> </main> ); } Setting dynamicParams = false means any slug not returned by generateStaticParams gets a real 404 instead of rendering an empty template. That prevents a whole class of accidental junk URLs, such as typos in links that would otherwise produce a soft 404.
Note that in recent Next.js versions params is a Promise, so it is awaited. If you are on an older version you will see it as a plain object.
Unique metadata per page
Every location page needs its own title, description and canonical URL. generateMetadata runs on the server alongside the page:
import type { Metadata } from "next"; export async function generateMetadata({ params, }: { params: Promise<{ slug: string }>; }): Promise<Metadata> { const { slug } = await params; const loc = getLocation(slug); if (!loc) return {}; const url = `https://www.example.com/locations/${loc.slug}`; return { title: `Web Design and Local SEO in ${loc.city}, ${loc.region}`, description: `Websites and local search for ${loc.city} businesses, serving ${loc.areasServed.slice(0, 3).join(", ")} and nearby areas.`, alternates: { canonical: url }, robots: loc.indexable ? undefined : { index: false, follow: true }, }; } Two details are worth calling out. The canonical is always self-referencing and always uses the same host, so you never end up with example.com and www.example.com versions competing. And the robots field reads the indexable flag, so drafts render for review but carry a noindex tag.
Keep the sitemap in sync
The sitemap should come from the same data, filtered by the same flag, so it can never list a page you have marked noindex:
// app/sitemap.ts import type { MetadataRoute } from "next"; import { locations } from "@/lib/locations"; export default function sitemap(): MetadataRoute.Sitemap { const base = "https://www.example.com"; return [ { url: `${base}/locations` }, ...locations .filter((l) => l.indexable) .map((l) => ({ url: `${base}/locations/${l.slug}` })), ]; } One source of truth for routes, metadata and sitemap removes the most common drift problem, where a page gets deleted but the sitemap keeps advertising it for months.
Internal linking is part of the feature
Location pages that are only reachable through the sitemap are orphans. Search engines find them but have little reason to treat them as important. Build links into the structure:
- A hub page at
/locationsthat lists every indexable city with a short line about each - Links from each location page to the relevant service pages
- Links from service pages back to the locations where that service is offered
- A small "nearby areas" block on each city page linking to neighboring cities
For a working example of the hub and spoke pattern, the CodeHunterz locations hub lists each city page and links into the matching service pages, so every location is two clicks from the homepage.
The nearby block is easy to derive if you store coordinates or a manual neighbor list. A manual list is usually better, because "nearby" for a service business means "on the same route," not straight-line distance.
Add LocalBusiness schema with areaServed
Structured data helps search engines connect each page to the business and the area it covers. For a service area business without a storefront in every city, use areaServed rather than inventing addresses:
function LocationSchema({ loc }: { loc: Location }) { const data = { "@context": "https://schema.org", "@type": "ProfessionalService", name: "Example Co", url: `https://www.example.com/locations/${loc.slug}`, areaServed: loc.areasServed.map((name) => ({ "@type": "Place", name: `${name}, ${loc.city}`, })), }; return ( <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }} /> ); } Never put a fake street address on a city page to look local. It misleads users, and it conflicts with the business information search engines already have.
A build-time guard against thin pages
Rules in a document get ignored. Rules in the build do not. A small check can fail the build if an indexable location is missing real content:
// scripts/check-locations.ts import { locations } from "../lib/locations"; const problems: string[] = []; const intros = new Set<string>(); for (const l of locations.filter((x) => x.indexable)) { if (l.intro.split(" ").length < 60) problems.push(`${l.slug}: intro too short`); if (l.faqs.length < 3) problems.push(`${l.slug}: fewer than 3 FAQs`); if (l.localNotes.length < 2) problems.push(`${l.slug}: needs local notes`); if (intros.has(l.intro)) problems.push(`${l.slug}: duplicate intro`); intros.add(l.intro); } if (problems.length) { console.error(problems.join("\n")); process.exit(1); } Run it in prebuild in package.json. The thresholds are arbitrary and you should tune them, but having any automated floor changes behavior. Nobody can quietly add twenty cities with copied intros.
You can go further by comparing text similarity between pages, but in practice the duplicate check plus required fields catches the worst cases.
Performance still counts
Location pages often get traffic from mobile searches by people who need help now. Since every page here is statically generated, the HTML is fast by default. The usual things still slow pages down:
- A large hero image on every city page. Use
next/imagewith explicit sizes and only mark the first visible image as priority. - Embedding a map iframe at the top of the page. Lazy load it below the fold, or use a static image linked to the map.
- Loading a chat widget or tracking scripts eagerly. Use
next/scriptwithlazyOnloadfor anything not needed on first paint.
A click-to-call link near the top of the page is often more useful to a local visitor than any of those heavy elements.
When not to build location pages
Sometimes the right engineering decision is to push back on the request. If the business genuinely serves one metro area with no meaningful differences between suburbs, one strong service area page will usually do better than fifteen weak ones. Good local SEO is about relevance and trust, not page count.
A reasonable rule: add a location page when you have something true and specific to say about that location, and the business actually wants calls from there. Otherwise list the area on a single service area page and move on. The CodeHunterz guide on SEO for service area businesses covers that decision from the marketing side, which is useful context to share with the client.
Summary
- Model the data that actually differs between locations before writing a template.
- Use
generateStaticParamswithdynamicParams = falseso only real locations exist. - Generate unique metadata and self-referencing canonicals per page.
- Drive the sitemap and robots rules from the same
indexableflag. - Link locations into a hub and into service pages so none are orphaned.
- Use
areaServedin schema instead of invented addresses. - Add a prebuild check so thin pages cannot ship.
If you want to see how this structure looks on a production site, or you need help planning one, the team behind these notes builds Next.js sites for local businesses using this same pattern.
CodeHunterz Team