The Pagination component renders previous/next links and a page status
indicator. It’s designed to work with Astro’s built-in
paginate() function.
---
import Pagination from "astro-theme-university/components/Pagination.astro";
---
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
page * | {
url: {
prev: string | undefined;
next: string | undefined;
};
currentPage: number;
lastPage: number;
} | --- | Astro pagination object from `getStaticPaths`. |
Usage with paginate()#
The typical pattern is a [...page].astro dynamic route:
---
import { getCollection } from "astro:content";
import Pagination from "astro-theme-university/components/Pagination.astro";
export async function getStaticPaths({ paginate }) {
const posts = await getCollection("news");
const sorted = posts.sort(
(a, b) => b.data.date.getTime() - a.data.date.getTime(),
);
return paginate(sorted, { pageSize: 12 });
}
const { page } = Astro.props;
---
<ul>
{page.data.map((post) => <li>{post.data.title}</li>)}
</ul>
<Pagination page={page} />
The component shows “Previous” and “Next” links only when the corresponding page exists, with a “Page X of Y” status in between.