Astro’s “Invalid dynamic route” error means a parameter for a dynamic route like src/pages/blog/[slug].astro has a value Astro cannot use. Astro’s documentation for this error names two causes: a parameter that is undefined, and a value containing slashes that needs a rest parameter ([...slug]) instead of a single-segment one. Return a string for every parameter in getStaticPaths(), or rename the file to [...slug].astro.
Key Takeaways
- A
[slug]parameter matches one URL segment; it cannot holda/b.- Use
[...slug]when values contain slashes, such as nested content IDs.- Only rest parameters may be
undefined; that renders the route’s base path.- Current Astro 7 releases report most of these cases with more specific
getStaticPaths()errors.- The message shows the route, the parameter and the value it received.
The error
Invalid dynamic route.
The slug param for route /blog/[slug] is invalid. Received **undefined**.
Astro 7 still defines this error, but in the installed versions we checked (7.2.9 and 7.4.4) the core router reports most bad parameters through more specific errors, such as “Invalid route parameter returned by getStaticPaths()” for a parameter that is not a string. If you see this exact message, you are likely on an older Astro version or an integration raised it. The causes and fixes are the same.
Why it happens
Each bracketed part of a file name is a parameter. A single-segment parameter ([slug]) must be a non-empty string without /. Two mistakes cause most failures:
- A missing value.
params: { slug: post.data.slug }where some posts have noslugfield givesundefined. - Nested values. Content in
src/content/blog/2026/recap.mdhas the ID2026/recap, which spans two segments.
---
// src/pages/blog/[slug].astro (fails for nested posts)
import { getCollection } from 'astro:content';
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({ params: { slug: post.id }, props: { post } }));
}
---
Fix 1: use a rest parameter
Rename the file so the parameter can hold several segments:
# Terminal
git mv "src/pages/blog/[slug].astro" "src/pages/blog/[...slug].astro"
---
// src/pages/blog/[...slug].astro
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({ params: { slug: post.id }, props: { post } }));
}
const { post } = Astro.props;
const { Content } = await render(post);
---
<Content />
Now 2026/recap builds /blog/2026/recap/. A rest parameter may also be undefined, which builds /blog/ itself.
Fix 2: always return a string
If the route should stay single-segment, make sure every value exists and has no slashes:
return posts.map((post) => ({
params: { slug: post.id.replaceAll('/', '-') },
props: { post },
}));
Numbers must be converted too: { page: String(n) }. Our getStaticPaths guide covers params and props, and the invalid getStaticPaths param fix handles the closely related type error. The pages and routing docs explain file-based routes, and the official rest parameters section has more examples. Themes in our Blog & Editorial category use [...slug] for posts for this reason.
FAQ
What is the difference between [slug] and […slug] in Astro?
[slug] matches exactly one URL segment. [...slug] matches any number of segments, including none, so it can hold values like 2026/recap.
Can an Astro route parameter be a number?
No. Parameters must be strings, or undefined for rest parameters. Convert numbers with String() before returning them.
Why does my nested content break my Astro route?
Entries in subfolders have IDs with slashes. A single-segment [slug] route cannot match them; use [...slug].