From 377a25dc4c51c060e751aeba4d3f946a41de907a Mon Sep 17 00:00:00 2001 From: Cédric Bontems Date: Tue, 4 Jul 2023 00:06:16 +0200 Subject: Fix broken link on 404 page when `defaultLocale: 'root'` is set (#300) Co-authored-by: Chris Swithinbank --- .changeset/many-tips-battle.md | 5 +++++ packages/starlight/404.astro | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/many-tips-battle.md diff --git a/.changeset/many-tips-battle.md b/.changeset/many-tips-battle.md new file mode 100644 index 00000000..1e972e88 --- /dev/null +++ b/.changeset/many-tips-battle.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": patch +--- + +Fix broken link on 404 page when `defaultLocale: 'root'` is set in `astro.config.mjs` diff --git a/packages/starlight/404.astro b/packages/starlight/404.astro index ecd95447..cdf76156 100644 --- a/packages/starlight/404.astro +++ b/packages/starlight/404.astro @@ -6,7 +6,10 @@ import Page from './layout/Page.astro'; import type { StarlightDocsEntry } from './utils/routing'; import { useTranslations } from './utils/translations'; -const { lang = 'en', dir = 'ltr', locale } = config.defaultLocale || {}; +const { lang = 'en', dir = 'ltr' } = config.defaultLocale || {}; +let locale = config.defaultLocale?.locale; +if (locale === 'root') locale = undefined; + const entryMeta = { dir, lang, locale }; const t = useTranslations(locale); @@ -34,6 +37,6 @@ const entry = userEntry || fallbackEntry; const { Content, headings } = await entry.render(); --- - + -- cgit