fix(router): error in the back button after refreshing the first time you enter the detail page

This commit is contained in:
hamster1963 2024-11-15 11:28:46 +08:00
parent 926d45b4be
commit 348519ed5b
2 changed files with 6 additions and 5 deletions

View File

@ -29,12 +29,9 @@ export default function ServerDetailClient({
}, []);
useEffect(() => {
const previousPath = sessionStorage.getItem("lastPath");
const previousPath = sessionStorage.getItem("fromMainPage");
if (previousPath) {
setHasHistory(true);
} else {
const currentPath = window.location.pathname;
sessionStorage.setItem("lastPath", currentPath);
}
}, []);

View File

@ -29,8 +29,12 @@ export default function ServerCard({
const fixedTopServerName =
getEnv("NEXT_PUBLIC_FixedTopServerName") === "true";
const saveSession = () => {
sessionStorage.setItem("fromMainPage", "true");
};
return online ? (
<Link href={`/${id}`} prefetch={true}>
<Link onClick={saveSession} href={`/${id}`} prefetch={true}>
<Card
className={cn(
"flex flex-col items-center justify-start gap-3 p-3 md:px-5 cursor-pointer",