fix: use window.location for locale switch to ensure URL change
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import { useRouter, usePathname } from "next/navigation";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore";
|
||||
@@ -21,7 +21,6 @@ interface HeaderProps {
|
||||
|
||||
export default function Header({ locale = "sr" }: HeaderProps) {
|
||||
const t = useTranslations("Header");
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
||||
@@ -52,7 +51,7 @@ export default function Header({ locale = "sr" }: HeaderProps) {
|
||||
document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`;
|
||||
const pathWithoutLocale = pathname.replace(/^\/(sr|en|de|fr)/, "") || "/";
|
||||
const newPath = `/${newLocale}${pathWithoutLocale}`;
|
||||
router.push(newPath);
|
||||
window.location.href = newPath;
|
||||
setLangDropdownOpen(false);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user