Skip to content

Commit

Permalink
fix: use relative path for non-specified router prefix
Browse files Browse the repository at this point in the history
Fixes #244
  • Loading branch information
harlan-zw committed Oct 16, 2024
1 parent 020998f commit 1bb0095
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export async function generateClient(options: GenerateClientOptions = {}, unligh

const { runtimeSettings, resolvedConfig, worker } = unlighthouse

const prefix = withTrailingSlash(withLeadingSlash(resolvedConfig.routerPrefix))
let prefix = withTrailingSlash(withLeadingSlash(resolvedConfig.routerPrefix))
// for non-specified paths we use relative
if (prefix === '/') {
prefix = ''
}
const clientPathFolder = dirname(runtimeSettings.resolvedClientPath)

await fs.copy(clientPathFolder, runtimeSettings.generatedClientPath)
Expand Down Expand Up @@ -84,8 +88,8 @@ export async function generateClient(options: GenerateClientOptions = {}, unligh
// should be a single entry
let indexJS = await fs.readFile(indexPath, 'utf-8')
indexJS = indexJS
.replace('const base = "/";', `const base = "${prefix}";`)
.replace('createWebHistory("/")', `createWebHistory("${prefix}")`)
.replace('const base = "/";', `const base = window.location.pathname;`)
.replace('createWebHistory("/")', `createWebHistory(window.location.pathname)`)
await fs.writeFile(indexPath.replace(clientPathFolder, runtimeSettings.generatedClientPath), indexJS, 'utf-8')
}
else {
Expand Down

0 comments on commit 1bb0095

Please sign in to comment.