Skip to content

Routing & Layouts

React gives you a blank canvas — you add a router yourself (react-router, TanStack Router, or the Next.js conventions). Astro takes a different approach: routing is built into the file system. Drop a .astro file into src/pages/ and it becomes a URL. No configuration, no <Route> components, no provider wrapping.

This module maps every routing and layout concept you already know from react-router or Next.js to the Astro equivalent.

LessonWhat you’ll learn
File-based routingsrc/pages/*.astro → URL segments
Dynamic routes[slug].astro + getStaticPaths() vs generateStaticParams
Layoutssrc/layouts/Layout.astro + <slot /> vs layout.tsx
NavigationPlain <a href> MPA model + Astro.url vs <Link> / useRouter

Coming from a React SPA or Next.js you might expect a client-side router. Astro uses a Multi-Page Application (MPA) model by default: every navigation triggers a full page request and the server returns fully-rendered HTML. This is identical to how the web worked before SPAs — and it makes Astro extremely fast by default.

React
// React SPA — client-side navigation
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
);
}
Astro
<!-- Astro MPA — no router, no JS needed -->
<!-- src/pages/index.astro -->
---
import Layout from '../layouts/Layout.astro';
---
<Layout>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<h1>Home</h1>
</Layout>
<!-- src/pages/about.astro → /about -->
What is the default routing model in Astro?
How do you create a new route in Astro?
Which component does Astro use for client-side navigation by default?