From 46b0a26969901b199fc0ff017655cf8bc7b0bfb1 Mon Sep 17 00:00:00 2001 From: Starystars67 Date: Thu, 8 Oct 2026 21:42:22 +0100 Subject: [PATCH] Show the not-found page instead of redirecting forever on an unknown address --- src/routes/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/routes/index.js b/src/routes/index.js index 9850d39..93fd67e 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -143,13 +143,20 @@ const router = createRouter({ // Global navigation guard for meta data and locale router.beforeEach(async (to, from, next) => { + // The language is the first part of the address. The not-found route matches + // anything, so it has no `locale` param even for /en/nope: read the language + // from the path itself, or /en/nope would look like it has none and be sent + // to /en/en/nope, then /en/en/en/nope, and never finish. + const firstSegment = to.path.split('/')[1] + const pathLocale = SUPPORT_LOCALES.includes(firstSegment) ? firstSegment : null + // If the path has no locale prefix (e.g. /servers), redirect to //servers - if (!to.params.locale && to.path !== '/') { + if (!to.params.locale && !pathLocale && to.path !== '/') { const locale = localStorage.getItem('lang') || 'en' return next(`/${locale}${to.path}`) } - const paramsLocale = to.params.locale || 'en' + const paramsLocale = to.params.locale || pathLocale || 'en' const i18n = window.i18n // Ensure i18n is available