Routing
React Router / Next.js
Next.js
For new projects, it has more than page switching: it's built to rank well in search and comes with ways to publish your site. This site is built with Next.js too
Compare the result
We built the same thing with each library. Try them out.
Compare the code
Edit the code and the preview on the right updates.
Building the same thing with Next.js
app/page.tsx → /
export default function Page() {
return <h2>Home</h2>
}app/items/page.tsx → /items
import Link from "next/link"
import { items } from "@/data/items"
export default function Page() {
return (
<div>
<h2>Products</h2>
<ul>
{items.map((item) => (
<li key={item.slug}>
<Link href={"/items/" + item.slug}>{item.name}</Link>
</li>
))}
</ul>
</div>
)
}app/items/[slug]/page.tsx → /items/apple, etc.
import Link from "next/link"
import { notFound } from "next/navigation"
import { items } from "@/data/items"
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
// Take the [slug] part of the URL (e.g. apple)
const { slug } = await params
const item = items.find((i) => i.slug === slug)
if (!item) {
notFound()
}
return (
<div>
<h2>{item.name}</h2>
<p>${item.price.toFixed(2)}</p>
<Link href="/items">← Back to the list</Link>
</div>
)
}Comparison
As of October 2026
React Router
Official site ↗Features
A library that adds page switching to a React app. You write a table in code that says "this URL shows this screen". Pages are built in the browser
Best for
Adding pages to an existing React app. Apps that don't need to show up in search, like admin screens behind a login
Features
A framework for building sites with React. Your folder and file structure becomes the URL (app/basics/page.tsx → /basics). Pages are built on the server before being sent
Best for
Building a new site you want to show up in search: blogs, shops, product pages, and so on