refactor(router): introduce app navigation manager

This commit is contained in:
2026-07-03 14:09:13 +08:00
parent 8a586e4471
commit 91dde42f92
23 changed files with 669 additions and 277 deletions
-13
View File
@@ -8,22 +8,14 @@
* 不再承担全局状态同步职责。
*/
import { useEffect, useRef } from "react";
import { usePathname, useRouter } from "next/navigation";
import { AuthStorage } from "@/data/storage/auth";
import { useAuthState } from "@/stores/auth/auth-context";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { PROTECTED_ROUTES, ROUTES, type StaticRoute } from "@/router/routes";
function isProtectedPath(pathname: string): boolean {
return PROTECTED_ROUTES.some((route: StaticRoute) => pathname === route);
}
export function ChatAuthSync() {
const authState = useAuthState();
const chatDispatch = useChatDispatch();
const pathname = usePathname();
const router = useRouter();
const prevSessionKeyRef = useRef<string | null>(null);
useEffect(() => {
@@ -35,9 +27,6 @@ export function ChatAuthSync() {
if (authState.loginStatus === "notLoggedIn") {
chatDispatch({ type: "ChatLogout" });
if (isProtectedPath(pathname)) {
router.replace(ROUTES.splash);
}
return;
}
@@ -65,8 +54,6 @@ export function ChatAuthSync() {
authState.isLoading,
authState.loginStatus,
chatDispatch,
pathname,
router,
]);
return null;