Skip to content

Commit b360ac8

Browse files
authoredApr 28, 2024··
fix(dev): match dev and prod routing behavior (#3837)
1 parent a0f7b94 commit b360ac8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎src/client/app/index.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,21 @@ function newRouter(): Router {
137137
pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js')
138138
}
139139

140-
if (import.meta.env.SSR) {
141-
pageModule = import(/*@vite-ignore*/ pageFilePath + '?t=' + Date.now())
140+
if (import.meta.env.DEV) {
141+
pageModule = import(/*@vite-ignore*/ pageFilePath).catch(() => {
142+
// try with/without trailing slash
143+
// in prod this is handled in src/client/app/utils.ts#pathToFile
144+
const url = new URL(pageFilePath!, 'http://a.com')
145+
const path =
146+
(url.pathname.endsWith('/index.md')
147+
? url.pathname.slice(0, -9) + '.md'
148+
: url.pathname.slice(0, -3) + '/index.md') +
149+
url.search +
150+
url.hash
151+
return import(/*@vite-ignore*/ path)
152+
})
153+
} else if (import.meta.env.SSR) {
154+
pageModule = import(/*@vite-ignore*/ `${pageFilePath}?t=${Date.now()}`)
142155
} else {
143156
pageModule = import(/*@vite-ignore*/ pageFilePath)
144157
}

0 commit comments

Comments
 (0)
Please sign in to comment.