From 195d867ee9bb51a4c112534b34bda7bcd0c2c3f5 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Thu, 22 Dec 2022 10:28:02 +0100 Subject: [PATCH] fix: handle cleanUrls with subfolders when using a trailing slash (#1575) Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> --- src/client/app/utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 4e9687dbd84..77d1959c5ba 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -22,10 +22,7 @@ export function withBase(path: string) { export function pathToFile(path: string): string { let pagePath = path.replace(/\.html$/, '') pagePath = decodeURIComponent(pagePath) - if (pagePath.endsWith('/')) { - pagePath += 'index' - } - + pagePath = pagePath.replace(/\/$/, '/index') // /foo/ -> /foo/index if (import.meta.env.DEV) { // always force re-fetch content in dev pagePath += `.md?t=${Date.now()}` @@ -41,7 +38,11 @@ export function pathToFile(path: string): string { ) + '.md' // client production build needs to account for page hash, which is // injected directly in the page's html - const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] + let pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] + if (!pageHash && pagePath.endsWith('_index.md')) { + pagePath = pagePath.slice(0, -9) + '.md' + pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] + } pagePath = `${base}assets/${pagePath}.${pageHash}.js` } else { // ssr build uses much simpler name mapping