Skip to content

Commit

Permalink
fix(dev): match dev and prod routing behavior (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Apr 28, 2024
1 parent a0f7b94 commit b360ac8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/client/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b360ac8

Please sign in to comment.