|
@@ -1,4 +1,6 @@
|
|
|
"use client";
|
|
|
+import { useEffect } from "react";
|
|
|
+import { useRouter } from "next/navigation";
|
|
|
import { Link } from "@/i18n/routing";
|
|
|
import { useWalletStore } from "@/stores/useWalletStore";
|
|
|
import { getToken } from "@/utils/Cookies";
|
|
@@ -6,42 +8,51 @@ import { useTranslations } from "next-intl";
|
|
|
import styles from "./style.module.scss";
|
|
|
|
|
|
const HeaderRight = () => {
|
|
|
- const t = useTranslations("Header");
|
|
|
+ const router = useRouter();
|
|
|
+ const t = useTranslations("Header");
|
|
|
|
|
|
- const token = getToken();
|
|
|
- const score = useWalletStore((state) => state.wallet.score);
|
|
|
+ const token = getToken();
|
|
|
+ const score = useWalletStore((state) => state.wallet.score);
|
|
|
|
|
|
- return (
|
|
|
- <div className={styles.headerRight}>
|
|
|
- <div className={styles.right}>
|
|
|
- {token ? (
|
|
|
- <>
|
|
|
- <Link
|
|
|
- href={"/profile"}
|
|
|
- className={"flex items-center text-[0.12rem]"}
|
|
|
- prefetch
|
|
|
- >
|
|
|
- <i className={"iconfont icon-yonghu mr-[0.03rem]"}></i>
|
|
|
- <span>{score}</span>
|
|
|
- </Link>
|
|
|
+ // ✅ 主动预加载常用页面,仅在浏览器 + router ready 时执行
|
|
|
+ useEffect(() => {
|
|
|
+ router.prefetch("/profile");
|
|
|
+ router.prefetch("/deposit");
|
|
|
+ router.prefetch("/login?redirect=/");
|
|
|
+ router.prefetch("/register?redirect=/");
|
|
|
+ }, []);
|
|
|
|
|
|
- <Link href={"/deposit"} prefetch className={styles.rightActive}>
|
|
|
- {t("deposit")}
|
|
|
- </Link>
|
|
|
- </>
|
|
|
- ) : (
|
|
|
- <>
|
|
|
- <Link href={"/login?redirect=/"} prefetch className={styles.leftActive}>
|
|
|
- {t("login")}
|
|
|
- </Link>
|
|
|
- <Link href={"/register?redirect=/"} prefetch className={styles.rightActive}>
|
|
|
- {t("register")}
|
|
|
- </Link>
|
|
|
- </>
|
|
|
- )}
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- );
|
|
|
+ return (
|
|
|
+ <div className={styles.headerRight}>
|
|
|
+ <div className={styles.right}>
|
|
|
+ {token ? (
|
|
|
+ <>
|
|
|
+ <Link
|
|
|
+ href={"/profile"}
|
|
|
+ className={"flex items-center text-[0.12rem]"}
|
|
|
+ prefetch
|
|
|
+ >
|
|
|
+ <i className={"iconfont icon-yonghu mr-[0.03rem]"}></i>
|
|
|
+ <span>{score}</span>
|
|
|
+ </Link>
|
|
|
+
|
|
|
+ <Link href={"/deposit"} prefetch className={styles.rightActive}>
|
|
|
+ {t("deposit")}
|
|
|
+ </Link>
|
|
|
+ </>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Link href={"/login?redirect=/"} prefetch className={styles.leftActive}>
|
|
|
+ {t("login")}
|
|
|
+ </Link>
|
|
|
+ <Link href={"/register?redirect=/"} prefetch className={styles.rightActive}>
|
|
|
+ {t("register")}
|
|
|
+ </Link>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
export default HeaderRight;
|