diff options
| author | copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> | 2026-04-25 12:30:41 +0000 |
|---|---|---|
| committer | Bertrand Yuan <189593334+bertyuan@users.noreply.github.com> | 2026-04-27 14:50:52 +0800 |
| commit | a5e4155a752fa090c7bc3751a803b4359453e56c (patch) | |
| tree | cb722c79333c839884195f2697365e4df0dfe47e /src/app/(main)/(home)/posts/page.tsx | |
| parent | 8b9c0139a93c8b9d41068e5271d0fc6917d34fab (diff) | |
fix: frontend-backend connection bugs
Agent-Logs-Url: https://github.com/bertyuan/next-blog/sessions/f86da32b-3af7-4393-8077-ce3435137221
Co-authored-by: bertyuan <189593334+bertyuan@users.noreply.github.com>
Diffstat (limited to 'src/app/(main)/(home)/posts/page.tsx')
| -rw-r--r-- | src/app/(main)/(home)/posts/page.tsx | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/app/(main)/(home)/posts/page.tsx b/src/app/(main)/(home)/posts/page.tsx index 40ebcda..daced35 100644 --- a/src/app/(main)/(home)/posts/page.tsx +++ b/src/app/(main)/(home)/posts/page.tsx @@ -58,12 +58,14 @@ export default async function Page(props: { const pageIndex = searchParams.page ? Number.parseInt( Array.isArray(searchParams.page) - ? searchParams.page[0] ?? '' + ? (searchParams.page[0] ?? '') : searchParams.page, - 10 + 10, ) - 1 : 0; + if (Number.isNaN(pageIndex)) notFound(); + // 获取文章(带分页) const { posts, totalDocs, totalPages } = await getPublishedPosts({ limit: postsPerPage, @@ -106,7 +108,9 @@ export default async function Page(props: { })} </div> </Section> - {totalPages > 1 && <Pagination pageIndex={pageIndex} pageCount={totalPages} />} + {totalPages > 1 && ( + <Pagination pageIndex={pageIndex} pageCount={totalPages} /> + )} </> ); } @@ -118,12 +122,17 @@ type Props = { export async function generateMetadata( props: Props, - parent: ResolvingMetadata + parent: ResolvingMetadata, ): Promise<Metadata> { const searchParams = await props.searchParams; const pageIndex = searchParams.page - ? Number.parseInt(searchParams.page as string, 10) + ? Number.parseInt( + Array.isArray(searchParams.page) + ? (searchParams.page[0] ?? '') + : searchParams.page, + 10, + ) : 1; const isFirstPage = pageIndex === 1 || !searchParams.page; |
