Astro throws “Page number param not found” when you call paginate() inside getStaticPaths() in a route file that has no page parameter. paginate() always writes the page number into a param called page, so the file must be named [page].astro or [...page].astro. Rename the file and the error goes away.
Key Takeaways
- The param name is fixed:
page.[p].astroor[num].astrowon’t work.[page].astrogives/blog/1/,/blog/2/;[...page].astrogives/blog/,/blog/2/.- Other params can sit alongside it, like
src/pages/[tag]/[page].astro.- Pass extra params through
paginate(items, { params: { tag } }).
The exact error
Page number param not found.
[paginate()] page number param `page` not found in your filepath.
Hint: Rename your file to `[page].astro` or `[...page].astro`.
What causes it
When paginate() runs, Astro checks the route’s params for page or ...page. If neither exists, it can’t decide where to put the page number. Typical triggers:
- The file is
src/pages/blog/index.astroorsrc/pages/blog.astro, with no dynamic segment at all. - The param has another name:
src/pages/blog/[p].astroor[pageNumber].astro. - The param is
[slug].astrobecause the file was copied from a post template.
The fix
Rename the file. Choose the form based on the URL you want for page 1:
| File | Page 1 URL | Page 2 URL |
|---|---|---|
src/pages/blog/[page].astro |
/blog/1/ |
/blog/2/ |
src/pages/blog/[...page].astro |
/blog/ |
/blog/2/ |
The rest-param form is what most blogs want, because the first page lives at the clean section URL:
---
// src/pages/blog/[...page].astro
import { getCollection } from 'astro:content';
export async function getStaticPaths({ paginate }) {
const posts = (await getCollection('blog'))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
return paginate(posts, { pageSize: 10 });
}
const { page } = Astro.props;
---
<ul>
{page.data.map((post) => <li><a href={`/blog/${post.id}/`}>{post.data.title}</a></li>)}
</ul>
{page.url.prev && <a href={page.url.prev}>Newer posts</a>}
{page.url.next && <a href={page.url.next}>Older posts</a>}
If you also have src/pages/blog/index.astro, delete it or move its content into the paginated route, because both files would claim /blog/.
Pagination with another param
For tag or category archives, keep page as the last segment and pass the other param in:
---
// src/pages/tags/[tag]/[...page].astro
import { getCollection } from 'astro:content';
export async function getStaticPaths({ paginate }) {
const posts = await getCollection('blog');
const tags = [...new Set(posts.flatMap((p) => p.data.tags))];
return tags.flatMap((tag) =>
paginate(posts.filter((p) => p.data.tags.includes(tag)), {
params: { tag },
pageSize: 10,
}),
);
}
const { page } = Astro.props;
const { tag } = Astro.params;
---
<h1>Posts tagged {tag}</h1>
For ready-made blog layouts with archives, see the Blog & Editorial themes. The content collections docs explain the collection side, and if getStaticPaths() itself is missing, see getStaticPaths() required. Astro’s pagination guide lists every page prop.
FAQ
How do I paginate in Astro?
Name the route [page].astro or [...page].astro, and return paginate(items, { pageSize }) from getStaticPaths(). The current page is in Astro.props.page.
Can I rename the page param in Astro pagination?
No. paginate() always uses page. If you want different URLs, change the folder structure around it, for example src/pages/archive/[...page].astro.
Why is my first page at /blog/1/ instead of /blog/?
The file is [page].astro. Rename it to [...page].astro so page 1 renders at /blog/ and later pages at /blog/2/.