Pagination
URL-driven page state via searchParams. The loader slices the dataset by ?page=N; links navigate the browser, no client JS. Refresh, share, and back/forward all work because the page number lives in the URL.
Tip
Every ?page=N URL is bookmarkable and crawlable — unlike client-side state. Combine server pagination with infinite scroll by pre-rendering page 1 then fetching subsequent pages via the same URL.
Rows 1–10 of 47
- #01 · Item 01
- #02 · Item 02
- #03 · Item 03
- #04 · Item 04
- #05 · Item 05
- #06 · Item 06
- #07 · Item 07
- #08 · Item 08
- #09 · Item 09
- #10 · Item 10
// Page reads ?page from searchParams; loader returns the slice +
// pagination metadata. Links carry ?page=N — no client JS, no
// state. Browser back/forward Just Works.
export async function loader({ request }) {
const url = new URL(request.url);
const page = Math.max(1, parseInt(url.searchParams.get("page") ?? "1", 10));
const start = (page - 1) * PAGE_SIZE;
return {
rows: items.slice(start, start + PAGE_SIZE),
page,
totalPages: Math.ceil(items.length / PAGE_SIZE),
};
}
// Render: <a href={"?page=" + (page - 1)}>← prev</a>