diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 3534856..324a90b 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -3,6 +3,7 @@ import { ready } from './lib/crypto'; import { api, ApiError } from './lib/api'; import { session, setSessionUserOnly } from './lib/session.svelte'; + import { goBack } from './lib/navigate'; import { logout } from './lib/auth'; import Login from './components/Login.svelte'; import Signup from './components/Signup.svelte'; @@ -138,7 +139,18 @@ // No session — fine. } - applyRoute(route); + // Cold-load redirect: a logged-in user landing on the public landing + // probably wants their own dashboard, not the marketing-y "what is this" + // page. We only redirect on this initial mount — not on every + // applyRoute call — so browser-back from /hjem to / still lets the + // explicit navigation through (no loop, and the wordmark intentionally + // sends logged-in users to /hjem instead of / anyway). + if (route.view === 'public-home' && session.user) { + pushUrl('/hjem'); + view = 'home'; + } else { + applyRoute(route); + } }); function applyRoute(route: Route) { @@ -164,22 +176,20 @@ } } - function leaveTag() { - // Same logic as leavePersonvern — back to wherever they were. - if (session.user) goHome(); - else goPublicHome(); - } - function goPersonvern() { pushUrl('/personvern'); view = 'personvern'; } - function leavePersonvern() { - // Send the visitor wherever they "would have been" — landing if logged out, - // dashboard if logged in. Either is more useful than staying on the doc page. - if (session.user) goHome(); - else goPublicHome(); + /** + * Back-button handler for sub-views (permalink, tag page, personvern, + * public list). Uses real browser history so the user returns to + * wherever they came from in the SPA — /hjem, /etiketter/foo, + * /aktivitet/bar, anywhere. Falls back to /hjem (or / when anonymous) + * on cold-loads where there's no prior history entry. + */ + function backToCallerOrHome() { + goBack(session.user ? '/hjem' : '/'); } function onAuthed() { @@ -207,7 +217,8 @@