-
+
-
+
-
+
Junior
-
+
Tröjor
-
+
Byxor
@@ -66,12 +67,12 @@ const Header: FC = () => {
-
+
- )
-}
+ );
+};
-export default Header
+export default Header;
diff --git a/components/ui/locale-switcher/locale-switcher.tsx b/components/ui/locale-switcher/locale-switcher.tsx
index 203ab0715..b471bd9c4 100644
--- a/components/ui/locale-switcher/locale-switcher.tsx
+++ b/components/ui/locale-switcher/locale-switcher.tsx
@@ -10,20 +10,34 @@ import { useState } from 'react';
import { i18n } from '../../../i18n-config';
interface LocaleSwitcherProps {
- current: string;
- pageData: object;
+ currentLocale: string;
+ localeData: {
+ type: string;
+ locale: string;
+ translations: [];
+ };
}
-export default function LocaleSwitcher({ current, pageData }: LocaleSwitcherProps) {
+export default function LocaleSwitcher({ currentLocale, localeData }: LocaleSwitcherProps) {
const pathName = usePathname();
-
- console.log(pageData);
+ const translations = localeData.translations;
const redirectedPathName = (locale: string) => {
- if (!pathName) return '/';
- const segments = pathName.split('/');
- segments[1] = locale;
- return segments.join('/');
+ if (!pathName || translations.length === 0) return '/';
+
+ if (translations.length > 0) {
+ const translation = translations.find((obj) => {
+ return obj['locale'] === locale;
+ });
+
+ if (translation) {
+ const url = `/${translation['locale']}${translation['slug']}`;
+
+ return url;
+ }
+ }
+
+ return '/';
};
const [isOpen, setIsOpen] = useState(false);
@@ -34,18 +48,18 @@ export default function LocaleSwitcher({ current, pageData }: LocaleSwitcherProp
{i18n.locales.map((locale) => {
- if (current === locale.id) {
+ if (currentLocale === locale.id) {
return;
} else {
return (
diff --git a/lib/sanity/queries.tsx b/lib/sanity/queries.tsx
index 62507fd09..1e35dcbff 100644
--- a/lib/sanity/queries.tsx
+++ b/lib/sanity/queries.tsx
@@ -160,7 +160,7 @@ export const reusableSection = `
`;
// Homepage query
-export const homePageQuery = `*[_type == "home" && slug.current == "/" && language == $locale][0] {
+export const homePageQuery = `*[_type == "home" && language == $locale][0] {
_type,
title,
"slug": slug.current,