···99)
10101111/**
1212- * Check if it's safe to navigate back (previous page was same origin).
1313- * Uses document.referrer to verify the user came from this site.
1212+ * Check if it's safe to navigate back.
1313+ * Uses the router's history state to verify there's a previous page in the SPA navigation history.
1414 */
1515function canGoBack(): boolean {
1616 if (import.meta.server) return false
1717 if (window.history.length <= 1) return false
1818- const referrer = document.referrer
1919- if (!referrer) return false
2020- try {
2121- return new URL(referrer).origin === window.location.origin
2222- } catch {
2323- return false
2424- }
1818+1919+ // Check if we have a valid position in the history state
2020+ // This works correctly with client-side SPA navigation (unlike document.referrer)
2121+ const state = window.history.state as { position?: number } | null
2222+ return state?.position != null && state.position > 0
2523}
26242725function goBack() {