From 772f7a5136e93d14cdc1161c3ece5d5497938e32 Mon Sep 17 00:00:00 2001 From: Zane Staggs Date: Thu, 4 Sep 2025 09:50:03 -0700 Subject: [PATCH] Use window.history.replaceState() instead of window.location.hash for all navigation --- ui/desktop/src/App.tsx | 6 +++--- ui/desktop/src/main.ts | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ui/desktop/src/App.tsx b/ui/desktop/src/App.tsx index e3157f965af1..d43b4a0b9ee4 100644 --- a/ui/desktop/src/App.tsx +++ b/ui/desktop/src/App.tsx @@ -554,12 +554,12 @@ export function AppInner() { view: viewFromUrl, }; window.history.replaceState( - {}, + initialViewOptions, '', - `/recipe-editor?${new URLSearchParams(initialViewOptions).toString()}` + `#/recipe-editor?${new URLSearchParams(initialViewOptions).toString()}` ); } else { - window.history.replaceState({}, '', `/${viewFromUrl}`); + window.history.replaceState({}, '', `#/${viewFromUrl}`); } } window.electron.on('set-view', handleSetView); diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index 84da69a97e5e..89352c52ed03 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -760,11 +760,19 @@ const createChat = async ( if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { mainWindow.loadURL(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}/#/${queryParams}`); } else { - // In production, we need to use a proper file protocol URL with correct base path - const indexPath = path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html/#/`); - mainWindow.loadFile(indexPath, { - search: queryParams ? queryParams.slice(1) : undefined, - }); + // In production, load the HTML file first, then set the hash route + const indexPath = path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`); + + // Load the file without hash + await mainWindow.loadFile(indexPath); + + // After the file loads, set the hash route programmatically + if (queryParams) { + const hashRoute = queryParams.startsWith('?') ? `#/${queryParams}` : `#/?${queryParams}`; + await mainWindow.webContents.executeJavaScript(` + window.history.replaceState({}, '', '${hashRoute}'); + `); + } } // Set up local keyboard shortcuts that only work when the window is focused