refactor(router): centralize app route transitions
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { MobileShell } from "@/app/_components/core";
|
||||
import { hasBusinessLoginToken } from "@/lib/auth/auth_session";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
|
||||
import { ROUTES } from "@/router/routes";
|
||||
import { pwaUtil, Logger } from "@/utils";
|
||||
|
||||
import {
|
||||
@@ -25,13 +24,13 @@ if (typeof window !== "undefined") {
|
||||
}
|
||||
|
||||
export function SplashScreen() {
|
||||
const router = useRouter();
|
||||
const navigator = useAppNavigator();
|
||||
const state = useAuthState();
|
||||
const authDispatch = useAuthDispatch();
|
||||
|
||||
const handleSkip = () => {
|
||||
authDispatch({ type: "AuthGuestLoginSubmitted" });
|
||||
router.replace(ROUTES.chat);
|
||||
navigator.openChat({ replace: true });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -49,13 +48,13 @@ export function SplashScreen() {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
if (!cancelled && (await hasBusinessLoginToken())) {
|
||||
router.replace(ROUTES.chat);
|
||||
navigator.openChat({ replace: true });
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [router]);
|
||||
}, [navigator]);
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// useEffect ② 按钮刚派了事件(pendingRedirect=true) +
|
||||
@@ -76,12 +75,12 @@ export function SplashScreen() {
|
||||
|
||||
if (state.pendingRedirect && state.loginStatus !== "notLoggedIn") {
|
||||
log.debug(
|
||||
"[splash] useEffect ② → router.replace(/chat) [via pendingRedirect flag]",
|
||||
"[splash] useEffect ② → navigator.openChat [via pendingRedirect flag]",
|
||||
);
|
||||
authDispatch({ type: "AuthClearPendingRedirect" });
|
||||
router.replace(ROUTES.chat);
|
||||
navigator.openChat({ replace: true });
|
||||
}
|
||||
}, [state.loginStatus, state.pendingRedirect, authDispatch, router]);
|
||||
}, [state.loginStatus, state.pendingRedirect, authDispatch, navigator]);
|
||||
|
||||
return (
|
||||
<MobileShell background="var(--color-sidebar-background)">
|
||||
|
||||
Reference in New Issue
Block a user