refactor(router): centralize app route transitions
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
*
|
||||
*/
|
||||
import { useEffect, useSyncExternalStore } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { MobileShell } from "@/app/_components/core";
|
||||
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
|
||||
import { ROUTES } from "@/router/routes";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
|
||||
import { AuthBackground, AuthPanel } from "./components";
|
||||
import styles from "./components/auth-screen.module.css";
|
||||
@@ -20,7 +20,7 @@ const log = new Logger("AppAuthAuthScreen");
|
||||
export function AuthScreen() {
|
||||
const state = useAuthState();
|
||||
const authDispatch = useAuthDispatch();
|
||||
const router = useRouter();
|
||||
const navigator = useAppNavigator();
|
||||
const redirectTo = useSyncExternalStore(
|
||||
subscribeLocationSnapshot,
|
||||
readRedirectFromLocation,
|
||||
@@ -40,17 +40,17 @@ export function AuthScreen() {
|
||||
});
|
||||
|
||||
if (state.pendingRedirect && state.loginStatus !== "notLoggedIn") {
|
||||
log.debug("[auth-screen] useEffect → router.replace [via pendingRedirect flag]", {
|
||||
log.debug("[auth-screen] useEffect → navigator.replace [via pendingRedirect flag]", {
|
||||
redirectTo: safeRedirectTo,
|
||||
});
|
||||
authDispatch({ type: "AuthClearPendingRedirect" });
|
||||
router.replace(safeRedirectTo);
|
||||
navigator.replace(safeRedirectTo);
|
||||
}
|
||||
}, [
|
||||
state.loginStatus,
|
||||
state.pendingRedirect,
|
||||
authDispatch,
|
||||
router,
|
||||
navigator,
|
||||
safeRedirectTo,
|
||||
]);
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
/**
|
||||
* 认证面板:顶层 switch(Facebook / Email)+ 悬浮返回按钮
|
||||
*/
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { BackButton } from "@/app/_components";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
|
||||
|
||||
import { AuthEmailPanel } from "./auth-email-panel";
|
||||
@@ -14,7 +13,7 @@ import styles from "./auth-panel.module.css";
|
||||
export function AuthPanel() {
|
||||
const state = useAuthState();
|
||||
const dispatch = useAuthDispatch();
|
||||
const router = useRouter();
|
||||
const navigator = useAppNavigator();
|
||||
|
||||
const switchToFacebook = () =>
|
||||
dispatch({ type: "AuthPanelModeChanged", mode: "facebook" });
|
||||
@@ -25,7 +24,7 @@ export function AuthPanel() {
|
||||
if (state.authPanelMode === "email") {
|
||||
switchToFacebook();
|
||||
} else {
|
||||
router.back();
|
||||
navigator.back();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user