删除使用状态挂钩,并将其设为服务器组件。然后,搜索参数将作为 props 传入,假设您至少使用 Next v13,然后将该
onChange
方法更改为导航方法。如果您使用分页库,我几乎肯定它们会允许您自己设置按钮 href,如果您在没有库的情况下执行此操作,只需将这些按钮更改为 Next Link
s。那会是这样的:
export default function Pagi({searchParams:{page = 1}}) {
return (
<Pagination
isCompact
showControls
showShadow
color="primary"
page={page}
total={pages}
onChange={(page) => {
/// NOTE: replace this with href on each button. You'll have to look at the docs for @next-ui/org to figure out exactly what property that would involve, but it's not `onChange`.
window.location.href = `/yourPage?page=${page}`
}}
/>
);
}