From f5ce3af1865ccaf34bca067ad8a5299e76f9442b Mon Sep 17 00:00:00 2001 From: Mikhail Romanko Date: Sat, 24 Oct 2026 17:45:31 +0300 Subject: [PATCH] Fix issues with browser history --- frontend/src/App.jsx | 14 +++++++++++--- frontend/src/pages/RoomsPage.jsx | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 1c7764a..98d86fc 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -75,8 +75,16 @@ export default function App() { return () => window.removeEventListener('popstate', onPopState) }, []) - const navigate = (tab, room = null, noguard = false) => { - window.history.pushState({}, '', pathFor(tab, room, noguard)) + // `replace` swaps the current entry instead of adding one. Deliberate joins + // use it so the URL that pointed at the room (and the guard page behind it) + // does not stay in history — otherwise going back would land on it and rejoin. + const navigate = (tab, room = null, noguard = false, replace = false) => { + const path = pathFor(tab, room, noguard) + if (replace) { + window.history.replaceState({}, '', path) + } else { + window.history.pushState({}, '', path) + } setRoute({ tab, room: tab === 'rooms' ? room || null : null, noguard }) } @@ -133,7 +141,7 @@ export default function App() { navigate('rooms', room, noguard)} + onNavigate={(room, noguard, replace) => navigate('rooms', room, noguard, replace)} /> )} {activeTab === 'profile' && } diff --git a/frontend/src/pages/RoomsPage.jsx b/frontend/src/pages/RoomsPage.jsx index 3e56c47..1dcf30a 100644 --- a/frontend/src/pages/RoomsPage.jsx +++ b/frontend/src/pages/RoomsPage.jsx @@ -76,7 +76,10 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) { if (!target) return entered.current = target setPending(null) - onNavigate(target, true) + // If a room URL is already open (the guard page, or a previously visited + // room), replace that history entry so going back does not land on it and + // join again. From a room-less URL, push so the pre-join page is kept. + onNavigate(target, true, Boolean(routeRoom)) enter(target) }