feat(navigation): add external entry routing

This commit is contained in:
2026-07-09 14:43:28 +08:00
parent 0659e52d29
commit 9159f5346d
17 changed files with 398 additions and 152 deletions
@@ -1,64 +0,0 @@
"use client";
/**
* 深链落地:把 deviceId + fbid/avatarUrl 写进本地存储,然后跳 `/chat`。
*
* 设计:
* - 不走 Server `redirect()`:避免把 fbid 暴露在 URL 里。
* - deviceId / fbid / avatarUrl 统一交给 `lib/chat` 落地。
* - 写入完成后通过统一导航回到 `/chat`,URL 不留深链痕迹。
*/
import { useEffect, useState } from "react";
import { persistExternalBrowserChatDeepLink } from "@/lib/chat/chat_external_browser";
import { useAppNavigator } from "@/router/use-app-navigator";
import { Logger } from "@/utils";
const log = new Logger("AppChatDeviceidDeviceIdDeepLinkPersist");
interface DeepLinkPersistProps {
deviceId: string;
fbid: string | null;
avatarUrl: string | null;
}
export default function DeepLinkPersist({
deviceId,
fbid,
avatarUrl,
}: DeepLinkPersistProps) {
const navigator = useAppNavigator();
const [done, setDone] = useState(false);
useEffect(() => {
void (async () => {
try {
await persistExternalBrowserChatDeepLink({
deviceId,
facebookId: fbid,
avatarUrl,
});
} catch (err) {
// 写不进 localStorage 时(例如隐私模式)也不阻塞跳转;记录到 console 即可。
log.warn("[DeepLinkPersist] failed to persist", err);
} finally {
setDone(true);
navigator.openChat({ replace: true });
}
})();
}, [avatarUrl, deviceId, fbid, navigator]);
return (
<div
className="flex flex-1 items-center justify-center"
style={{ minHeight: "100dvh" }}
>
<div
aria-label={done ? "Redirecting" : "Loading"}
className="size-10 animate-spin rounded-full border-4 border-t-transparent"
style={{ borderColor: "var(--color-accent)" }}
/>
</div>
);
}
-35
View File
@@ -1,35 +0,0 @@
/**
* 深链入口(Server Component
*
* 对齐 Flutter `lib/router/app_router.dart:60-78` 的 `GoRoute(path: '/chat/deviceid/:deviceId')`
* 把 `deviceId` 路径参数与 `fbid` / `avatarUrl` 查询参数透传给 Client 组件
* `<DeepLinkPersist>`,由它把数据写入 localStorage 后通过统一导航回到 `/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}
/>
);
}