summaryrefslogtreecommitdiff
path: root/src/app/(main)/(home)/posts
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/(main)/(home)/posts')
-rw-r--r--src/app/(main)/(home)/posts/[slug]/page.client.tsx5
-rw-r--r--src/app/(main)/(home)/posts/page.tsx19
2 files changed, 17 insertions, 7 deletions
diff --git a/src/app/(main)/(home)/posts/[slug]/page.client.tsx b/src/app/(main)/(home)/posts/[slug]/page.client.tsx
index 7a97f56..13dbfeb 100644
--- a/src/app/(main)/(home)/posts/[slug]/page.client.tsx
+++ b/src/app/(main)/(home)/posts/[slug]/page.client.tsx
@@ -7,7 +7,7 @@ import { Icons } from '@/components/icons/icons';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import { Comments } from '@fuma-comment/react';
-import { redirect } from 'next/navigation';
+import { useRouter } from 'next/navigation';
import { useRef } from 'react';
import { toast } from 'sonner';
import { useCopyToClipboard } from 'usehooks-ts';
@@ -42,6 +42,7 @@ export function PostComments({
slug,
className,
}: { slug: string; className?: string }) {
+ const router = useRouter();
return (
<Comments
page={slug}
@@ -49,7 +50,7 @@ export function PostComments({
auth={{
type: 'api',
signIn: () => {
- redirect('/login');
+ router.push('/login');
},
}}
/>
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;