Hook browser back/forward to nav state

Push history on user-initiated navigation so 'Back' moves between
views instead of leaving the app.

- urlHash: add pushUrlHash/pushSettingsHash (pushState variants)
- useConversationRouter: pushState on nav; popstate resolves hash
  to conversation without re-pushing; switch over if-chain
- useAppShell: pushState on settings open; popstate syncs
  visibility; close via history.back() when we own the entry
- Tests: popstate coverage in appStartupHash + useAppShell
This commit is contained in:
Martin Fournier
2026-05-11 01:18:53 -04:00
parent 70cb133b24
commit 76f3a59d83
6 changed files with 246 additions and 7 deletions
+16
View File
@@ -171,9 +171,25 @@ export function updateUrlHash(conv: Conversation | null): void {
}
}
// Update URL hash and add a new browser history entry
export function pushUrlHash(conv: Conversation | null): void {
const newHash = getConversationHash(conv);
if (newHash !== window.location.hash) {
window.history.pushState(null, '', newHash || window.location.pathname);
}
}
export function updateSettingsHash(section: SettingsSection): void {
const newHash = getSettingsHash(section);
if (newHash !== window.location.hash) {
window.history.replaceState(null, '', newHash);
}
}
// Push a settings hash as a new browser history entry
export function pushSettingsHash(section: SettingsSection): void {
const newHash = getSettingsHash(section);
if (newHash !== window.location.hash) {
window.history.pushState(null, '', newHash);
}
}