Files
cozsweet-frontend-nextjs/src/app/chat/deviceid/[deviceId]/page.tsx
T

36 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 深链入口(Server Component
*
* 对齐 Flutter `lib/router/app_router.dart:60-78` 的 `GoRoute(path: '/chat/deviceid/:deviceId')`
* 把 `deviceId` 路径参数与 `fbid` / `avatarUrl` 查询参数透传给 Client 组件
* `<DeepLinkPersist>`,由它把数据写入 localStorage 后 `router.replace('/chat')`。
*
* Next.js 15+ 约定:`params` / `searchParams` 是 Promise,必须 await。
* Next.js 16 全局 helper `PageProps<'/literal'>` 由 `next dev` / `next build` /
* `next typegen` 生成。
*
* 这里不调用 `redirect()`:把 fbid / avatarUrl 暴露在 URL 上对用户不友好;
* 跳转推迟到 Client 完成持久化之后。
*/
import DeepLinkPersist from "./DeepLinkPersist";
export default async function ChatDeviceIdPage(
props: PageProps<"/chat/deviceid/[deviceId]">,
) {
const { deviceId } = await props.params;
const { avatarUrl, fbid } = await props.searchParams;
const fbidStr = Array.isArray(fbid) ? fbid[0] : fbid ?? null;
const avatarUrlStr = Array.isArray(avatarUrl)
? avatarUrl[0]
: avatarUrl ?? null;
return (
<DeepLinkPersist
deviceId={deviceId}
fbid={fbidStr}
avatarUrl={avatarUrlStr}
/>
);
}