From b360ac88df3bfd60e3498cc19066c0c90261ee4f Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 28 Apr 2024 09:55:16 +0530 Subject: [PATCH] fix(dev): match dev and prod routing behavior (#3837) --- src/client/app/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/app/index.ts b/src/client/app/index.ts index 911760a1a5ad..72cc5063802f 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -137,8 +137,21 @@ function newRouter(): Router { pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js') } - if (import.meta.env.SSR) { - pageModule = import(/*@vite-ignore*/ pageFilePath + '?t=' + Date.now()) + if (import.meta.env.DEV) { + pageModule = import(/*@vite-ignore*/ pageFilePath).catch(() => { + // try with/without trailing slash + // in prod this is handled in src/client/app/utils.ts#pathToFile + const url = new URL(pageFilePath!, 'http://a.com') + const path = + (url.pathname.endsWith('/index.md') + ? url.pathname.slice(0, -9) + '.md' + : url.pathname.slice(0, -3) + '/index.md') + + url.search + + url.hash + return import(/*@vite-ignore*/ path) + }) + } else if (import.meta.env.SSR) { + pageModule = import(/*@vite-ignore*/ `${pageFilePath}?t=${Date.now()}`) } else { pageModule = import(/*@vite-ignore*/ pageFilePath) }