crush-level-web/src/app/(auth)/share/[userId]/page.tsx

40 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-11-28 06:31:36 +00:00
import SharePage from './share-page'
import { HydrationBoundary } from '@tanstack/react-query'
import { dehydrate } from '@tanstack/react-query'
import { QueryClient } from '@tanstack/react-query'
import { aiUserKeys } from '@/lib/query-keys'
import { userService } from '@/services/user'
import { ApiError } from '@/types/api'
import { notFound } from 'next/navigation'
2025-11-13 08:38:25 +00:00
const Page = async ({ params }: { params: Promise<{ userId?: string }> }) => {
2025-11-28 06:31:36 +00:00
const { userId } = await params
2025-11-13 08:38:25 +00:00
if (!userId) {
2025-11-28 06:31:36 +00:00
notFound()
2025-11-13 08:38:25 +00:00
}
2025-11-28 06:31:36 +00:00
const queryClient = new QueryClient()
2025-11-13 08:38:25 +00:00
try {
// 预获取用户基本信息
await queryClient.fetchQuery({
queryKey: aiUserKeys.baseInfo({ aiId: Number(userId) }),
queryFn: () => userService.getAIUserBaseInfo({ aiId: Number(userId) }),
2025-11-28 06:31:36 +00:00
})
2025-11-13 08:38:25 +00:00
} catch (error) {
2025-11-28 06:31:36 +00:00
if (error instanceof ApiError && error.errorCode === '10010012') {
notFound()
2025-11-13 08:38:25 +00:00
}
// 其他错误不影响页面渲染,让客户端处理
}
return (
2025-11-28 06:31:36 +00:00
<HydrationBoundary state={dehydrate(queryClient)}>
2025-11-13 08:38:25 +00:00
<SharePage />
</HydrationBoundary>
2025-11-28 06:31:36 +00:00
)
2025-11-13 08:38:25 +00:00
}
2025-11-28 06:31:36 +00:00
export default Page