[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: fix navigation for back (#276)

authored by

abeer0 and committed by
GitHub
ad8e2120 484a8881

+7 -9
+7 -9
app/pages/settings.vue
··· 9 9 ) 10 10 11 11 /** 12 - * Check if it's safe to navigate back (previous page was same origin). 13 - * Uses document.referrer to verify the user came from this site. 12 + * Check if it's safe to navigate back. 13 + * Uses the router's history state to verify there's a previous page in the SPA navigation history. 14 14 */ 15 15 function canGoBack(): boolean { 16 16 if (import.meta.server) return false 17 17 if (window.history.length <= 1) return false 18 - const referrer = document.referrer 19 - if (!referrer) return false 20 - try { 21 - return new URL(referrer).origin === window.location.origin 22 - } catch { 23 - return false 24 - } 18 + 19 + // Check if we have a valid position in the history state 20 + // This works correctly with client-side SPA navigation (unlike document.referrer) 21 + const state = window.history.state as { position?: number } | null 22 + return state?.position != null && state.position > 0 25 23 } 26 24 27 25 function goBack() {