Pagination
Documentation and examples for the Pagination component.
When To Use
- When it will take a long time to load/render all items.
- If you want to browse the data by navigating through pages.
Example Usage
The Pagination component handles generating page links based on the current page, total pages, and a base URL.
astro
---
import Pagination from '@/components/navigation/Pagination.astro';
---
<Pagination currentPage={1} totalPages={5} /> With Base URL
You can provide a `baseUrl` prop to prefix all generated page links. For example, setting `baseUrl="/blog"` will generate links like `/blog?page=2`. If no `baseUrl` is provided, it uses `?page=X`.
astro
<Pagination currentPage={3} totalPages={10} baseUrl="/blog" /> Large Number of Pages
When there are many pages, the component automatically truncates the middle pages with ellipses to maintain a compact UI.
astro
<Pagination currentPage={5} totalPages={50} /> Variants
The Pagination component supports `button` (default), `dots`, and `lines` variants, which are especially useful for carousels.
astro
<Pagination variant="button" currentPage={2} totalPages={5} />
<Pagination variant="dots" currentPage={2} totalPages={5} />
<Pagination variant="lines" currentPage={2} totalPages={5} /> API Reference
| Property | Description | Type | Default |
|---|---|---|---|
| currentPage | The current active page. | number | 1 |
| totalPages | The total number of pages available. | number | 5 |
| baseUrl | The base URL to prefix to generated links. | string | '' |
| variant | The visual style of the pagination. | 'button' | 'dots' | 'lines' | 'button' |
| class | Additional CSS classes for custom styling. | string | - |