Catch all routes

This commit is contained in:
Henrik Larsson
2023-08-07 16:40:42 +02:00
parent a75a2e7feb
commit 6527974989
8 changed files with 93 additions and 53 deletions

View File

@@ -14,8 +14,6 @@ interface CardProps {
imageFormat?: 'square' | 'portrait' | 'landscape';
}
const placeholderImg = '/product-img-placeholder.svg';
const Card: FC<CardProps> = ({ className, title, image, link, text, imageFormat = 'square' }) => {
const rootClassName = cn('relative', className);
@@ -39,7 +37,7 @@ const Card: FC<CardProps> = ({ className, title, image, link, text, imageFormat
} else if (type === 'category') {
href = `/category/${link.internalLink.reference.slug.current}`;
} else {
return `${link.internalLink.reference.slug.current}`;
href = `${link.internalLink.reference.slug.current}`;
}
return (

View File

@@ -1,43 +1,47 @@
'use client';
import LanguageIcon from 'components/icons/language';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuTrigger
} from 'components/ui/dropdown/dropdown';
import { useLocale } from 'next-intl';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useState } from 'react';
import { supportedLanguages } from '../../../i18n-config';
interface LocaleSwitcherProps {
currentLocale: string;
localeData: {
type: string;
locale: string;
translations: [];
};
}
// interface LocaleSwitcherProps {
// localeData: {
// type: string;
// locale: string;
// translations: [];
// };
// }
export default function LocaleSwitcher({ currentLocale, localeData }: LocaleSwitcherProps) {
export default function LocaleSwitcher() {
const pathName = usePathname();
const translations = localeData.translations;
const currentLocale = useLocale();
// const translations = localeData.translations;
const redirectedPathName = (locale: string) => {
if (!pathName || translations.length === 0) return '/';
if (!pathName) return '/';
if (translations.length > 0) {
const translation = translations.find((obj) => {
return obj['locale'] === locale;
});
// if (translations.length > 0) {
// const translation = translations.find((obj) => {
// return obj['locale'] === locale;
// });
if (translation) {
const url = `/${translation['locale']}${translation['slug']}`;
// if (translation) {
// const url = `/${translation['locale']}${translation['slug']}`;
return url;
}
}
// return url;
// }
// }
return '/';
return `/${locale}`;
};
const [isOpen, setIsOpen] = useState(false);