Docs
分页
分页
带有页面导航、下一个和上一个链接的分页。
安装
¥Installation
pnpm dlx shadcn@latest add pagination
用法
¥Usage
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination"
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
</PaginationContent>
</Pagination>
Next.js
默认情况下,<PaginationLink />
组件将渲染 <a />
标签。
¥By default the <PaginationLink />
component will render an <a />
tag.
要使用 Next.js <Link />
组件,请对 pagination.tsx
进行以下更新。
¥To use the Next.js <Link />
component, make the following updates to pagination.tsx
.
+ import Link from "next/link"
- type PaginationLinkProps = ... & React.ComponentProps<"a">
+ type PaginationLinkProps = ... & React.ComponentProps<typeof Link>
const PaginationLink = ({...props }: ) => (
<PaginationItem>
- <a>
+ <Link>
// ...
- </a>
+ </Link>
</PaginationItem>
)
注意:我们正在对 cli 进行更新以自动为你执行此操作。
¥Note: We are making updates to the cli to automatically do this for you.