From 28ef0ea6f60ab33e9cf34ecef10e1515d84f7168 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Fri, 15 Sep 2023 19:40:01 +0530 Subject: [PATCH] fix(client): router in invalid state after 404 (#2972) --- src/client/app/index.ts | 23 +++++++++++++---------- src/client/theme-default/NotFound.vue | 1 - 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/client/app/index.ts b/src/client/app/index.ts index e613d84e..31e7884b 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -121,25 +121,28 @@ function newRouter(): Router { return createRouter((path) => { let pageFilePath = pathToFile(path) + let pageModule = null - if (!pageFilePath) return null + if (pageFilePath) { + if (isInitialPageLoad) { + initialPath = pageFilePath + } - if (isInitialPageLoad) { - initialPath = pageFilePath - } + // use lean build if this is the initial page load or navigating back + // to the initial loaded path (the static vnodes already adopted the + // static content on that load so no need to re-fetch the page) + if (isInitialPageLoad || initialPath === pageFilePath) { + pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js') + } - // use lean build if this is the initial page load or navigating back - // to the initial loaded path (the static vnodes already adopted the - // static content on that load so no need to re-fetch the page) - if (isInitialPageLoad || initialPath === pageFilePath) { - pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js') + pageModule = import(/*@vite-ignore*/ pageFilePath) } if (inBrowser) { isInitialPageLoad = false } - return import(/*@vite-ignore*/ pageFilePath) + return pageModule }, Theme.NotFound) } diff --git a/src/client/theme-default/NotFound.vue b/src/client/theme-default/NotFound.vue index 35c107f7..8861062f 100644 --- a/src/client/theme-default/NotFound.vue +++ b/src/client/theme-default/NotFound.vue @@ -37,7 +37,6 @@ onMounted(() => { class="link" :href="withBase(root)" :aria-label="theme.notFound?.linkLabel ?? 'go to home'" - target="_self" > {{ theme.notFound?.linkText ?? 'Take me home' }}