/** * Navigation-History über location.state. * Jeder Link fügt die aktuelle URL zum Stack hinzu. * Der Zurück-Button poppt den letzten Eintrag und gibt den Rest weiter. */ export interface NavState { history?: string[]; } /** * Erstellt den state für einen Link - fügt die aktuelle URL zum History-Stack hinzu. */ export function pushHistory(currentPath: string, locationState?: unknown): NavState { const prev = (locationState as NavState)?.history || []; return { history: [...prev, currentPath] }; } /** * Gibt die Zurück-URL und den verbleibenden History-Stack zurück. */ export function popHistory(locationState?: unknown, fallback?: string): { to: string; state: NavState } { const history = [...((locationState as NavState)?.history || [])]; const to = history.pop() || fallback || '/'; return { to, state: { history } }; }