type Props = { currentPage: number; totalPages: number; basePath: string; }; export default function Pagination( { currentPage, totalPages, basePath }: Props, ) { if (totalPages <= 1) { return
; } const firstPage = 1; const lastPage = totalPages; const prevPage = currentPage > 1 ? currentPage - 1 : null; const nextPage = currentPage < totalPages ? currentPage + 1 : null; const firstHref = pageUrlAt(basePath, firstPage); const lastHref = pageUrlAt(basePath, lastPage); const prevHref = prevPage ? pageUrlAt(basePath, prevPage) : null; const nextHref = nextPage ? pageUrlAt(basePath, nextPage) : null; return ( ); } function pageUrlAt(basePath: string, page: number): string { return page === 1 ? basePath : `${basePath}${page}/`; }