From 728cb15677f4f84b33bed6bb2f70f47600ea1057 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Fri, 3 May 2024 01:16:55 +0530 Subject: [PATCH] fix: render 404 page completely on client to infer locale from browser path (#3858) --- src/client/app/router.ts | 8 ++- src/client/theme-default/NotFound.vue | 50 +++++-------------- src/client/theme-default/composables/langs.ts | 9 +--- src/node/build/render.ts | 2 +- src/shared/shared.ts | 2 +- types/shared.d.ts | 6 ++- 6 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index e51b7f80faa0..035c416a29c8 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -156,7 +156,13 @@ export function createRouter( latestPendingPath = null route.path = inBrowser ? pendingPath : withBase(pendingPath) route.component = fallbackComponent ? markRaw(fallbackComponent) : null - route.data = notFoundPageData + const relativePath = inBrowser + ? pendingPath + .replace(/(^|\/)$/, '$1index') + .replace(/(\.html)?$/, '.md') + .replace(/^\//, '') + : '404.md' + route.data = { ...notFoundPageData, relativePath } } } } diff --git a/src/client/theme-default/NotFound.vue b/src/client/theme-default/NotFound.vue index 9ed917de2bfc..b9665142806b 100644 --- a/src/client/theme-default/NotFound.vue +++ b/src/client/theme-default/NotFound.vue @@ -1,55 +1,31 @@