Skip to content

Commit 1bb0095

Browse files
committed
fix: use relative path for non-specified router prefix
Fixes #244
1 parent 020998f commit 1bb0095

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/core/src/build.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export async function generateClient(options: GenerateClientOptions = {}, unligh
2727

2828
const { runtimeSettings, resolvedConfig, worker } = unlighthouse
2929

30-
const prefix = withTrailingSlash(withLeadingSlash(resolvedConfig.routerPrefix))
30+
let prefix = withTrailingSlash(withLeadingSlash(resolvedConfig.routerPrefix))
31+
// for non-specified paths we use relative
32+
if (prefix === '/') {
33+
prefix = ''
34+
}
3135
const clientPathFolder = dirname(runtimeSettings.resolvedClientPath)
3236

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

0 commit comments

Comments
 (0)