From 1bb0095a669fa6caef98360b87d9b4112d8144f9 Mon Sep 17 00:00:00 2001 From: harlan Date: Wed, 16 Oct 2024 14:19:38 +1100 Subject: [PATCH] fix: use relative path for non-specified router prefix Fixes #244 --- packages/core/src/build.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/src/build.ts b/packages/core/src/build.ts index d268fb0f..318baed7 100644 --- a/packages/core/src/build.ts +++ b/packages/core/src/build.ts @@ -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) @@ -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 {