Skip to content

Commit ad5b336

Browse files
committed
fix(i18n): redirect 404 home link to the canonical locale path
1 parent 75ebe14 commit ad5b336

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

src/pages/404.astro

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
---
2-
import Layout from "@layouts/Layout.astro"
3-
import { translations, defaultLocale, type Locale, locales } from "@i18n/translations"
2+
import Layout from '@layouts/Layout.astro'
3+
import { translations, defaultLocale, type Locale, locales } from '@i18n/translations'
44
55
const pathName = Astro.url.pathname
6-
const locale = pathName.split("/")[1] as Locale
6+
const locale = pathName.split('/')[1] as Locale
77
const t = locales.includes(locale) ? translations[locale] : translations[defaultLocale]
8+
const pathnameToRedirect = locales.includes(locale) && locale !== defaultLocale ? `/${locale}` : `/`
89
---
910

1011
<Layout title="404 — Page not found">
1112
<div class="h-screen flex flex-col items-center justify-center gap-6 bg-black text-white px-4">
12-
13-
<div class="w-12 h-12 rounded-xl bg-white/4 flex items-center justify-center border border-white/8">
14-
<svg class="w-6 h-6 text-white/40" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
15-
<path stroke-linecap="round" stroke-linejoin="round" d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 5.25h.008v.008H12v-.008Z" />
13+
<div
14+
class="w-12 h-12 rounded-xl bg-white/4 flex items-center justify-center border border-white/8"
15+
>
16+
<svg
17+
class="w-6 h-6 text-white/40"
18+
fill="none"
19+
viewBox="0 0 24 24"
20+
stroke="currentColor"
21+
stroke-width="1.5"
22+
aria-hidden="true"
23+
>
24+
<path
25+
stroke-linecap="round"
26+
stroke-linejoin="round"
27+
d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 5.25h.008v.008H12v-.008Z"
28+
></path>
1629
</svg>
1730
</div>
1831

@@ -25,14 +38,21 @@ const t = locales.includes(locale) ? translations[locale] : translations[default
2538
</div>
2639

2740
<a
28-
href={locales.includes(locale) ? `/${locale}` : `/${defaultLocale}`}
41+
href={pathnameToRedirect}
2942
class="flex items-center gap-2 px-4 py-2 rounded-lg bg-white/6 border border-white/10 text-sm text-neutral-300 hover:text-white hover:bg-white/10 transition-colors"
3043
>
31-
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" aria-hidden="true">
32-
<path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5 3 12m0 0 7.5-7.5M3 12h18" />
44+
<svg
45+
class="w-4 h-4"
46+
fill="none"
47+
viewBox="0 0 24 24"
48+
stroke="currentColor"
49+
stroke-width="2"
50+
aria-hidden="true"
51+
>
52+
<path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5 3 12m0 0 7.5-7.5M3 12h18"
53+
></path>
3354
</svg>
3455
{t.backToHome}
3556
</a>
36-
3757
</div>
38-
</Layout>
58+
</Layout>

0 commit comments

Comments
 (0)