From 3ef1b59848484b8f140484b0e7ceb9324baa11e6 Mon Sep 17 00:00:00 2001 From: Hamed Bahram Date: Fri, 17 Nov 2023 13:25:11 -0500 Subject: [PATCH] Update to remove default locale from URL --- app/[lang]/components/custom-link.tsx | 15 ++++++++++++++ app/[lang]/components/header.tsx | 13 ++++++++---- app/[lang]/components/locale-switcher.tsx | 25 ++++++++++++++++++++--- middleware.ts | 10 +++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 app/[lang]/components/custom-link.tsx diff --git a/app/[lang]/components/custom-link.tsx b/app/[lang]/components/custom-link.tsx new file mode 100644 index 0000000..f106df5 --- /dev/null +++ b/app/[lang]/components/custom-link.tsx @@ -0,0 +1,15 @@ +import Link from 'next/link' +import { i18n } from '@/i18n.config' + +interface CustomLinkProps { + href: string + lang: string + children: React.ReactNode + [key: string]: any +} + +export default function CustomLink({ href, lang, ...props }: CustomLinkProps) { + const isDefaultLang = lang === i18n.defaultLocale + const path = isDefaultLang ? href : `/${lang}${href}` + return +} diff --git a/app/[lang]/components/header.tsx b/app/[lang]/components/header.tsx index b9525b1..ad47347 100644 --- a/app/[lang]/components/header.tsx +++ b/app/[lang]/components/header.tsx @@ -1,7 +1,8 @@ -import Link from 'next/link' +import LocaleSwitcher from './locale-switcher' +import CustomLink from './custom-link' + import { Locale } from '@/i18n.config' import { getDictionary } from '@/lib/dictionary' -import LocaleSwitcher from './locale-switcher' export default async function Header({ lang }: { lang: Locale }) { const { navigation } = await getDictionary(lang) @@ -11,10 +12,14 @@ export default async function Header({ lang }: { lang: Locale }) {