Preserve Pathname on Lang Change
All checks were successful
SteamWarCI Build successful

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-23 15:07:04 +02:00
parent a8817115a3
commit a195b074a7

View File

@@ -23,6 +23,7 @@
import { t, l } from "astro-i18n";
import { onMount } from "svelte";
import { loggedIn } from "@repo/authv2.ts";
import { astroI18n } from "astro-i18n";
interface Props {
logo?: import("svelte").Snippet;
}
@@ -34,6 +35,8 @@
let accountBtn = $state<HTMLAnchorElement>();
let currentPage = $state(astroI18n.route);
$effect(() => {
if ($loggedIn) {
accountBtn!.href = l("/dashboard");
@@ -44,6 +47,11 @@
onMount(() => {
handleScroll();
document.addEventListener("astro:page-load", () => {
astroI18n.route = location.pathname;
currentPage = astroI18n.route;
});
});
function handleScroll() {
@@ -125,12 +133,12 @@
<div>
<a
data-astro-reload
href={l("/", {}, { targetLocale: typeof navigator !== "undefined" ? navigator.language.split("-")[0] : "de" })}
href={l(currentPage, {}, { targetLocale: typeof navigator !== "undefined" ? navigator.language.split("-")[0] : "de" })}
onclick={() => cookieStore.delete("MANUAL_LANGUAGE")}
class="btn btn-gray">Auto</a
>
<a data-astro-reload href={l("/", {}, { targetLocale: "de" })} onclick={() => cookieStore.set("MANUAL_LANGUAGE", "TRUE")} class="btn btn-gray">Deutsch</a>
<a data-astro-reload href={l("/", {}, { targetLocale: "en" })} onclick={() => cookieStore.set("MANUAL_LANGUAGE", "TRUE")} class="btn btn-gray">English</a>
<a data-astro-reload href={l(currentPage, {}, { targetLocale: "de" })} onclick={() => cookieStore.set("MANUAL_LANGUAGE", "TRUE")} class="btn btn-gray">Deutsch</a>
<a data-astro-reload href={l(currentPage, {}, { targetLocale: "en" })} onclick={() => cookieStore.set("MANUAL_LANGUAGE", "TRUE")} class="btn btn-gray">English</a>
</div>
</div>
</div>