File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,19 +9,17 @@ const availableLocales = computed(() =>
99)
1010
1111/**
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 .
1414 */
1515function canGoBack(): boolean {
1616 if (import .meta .server ) return false
1717 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
2523}
2624
2725function goBack() {
You can’t perform that action at this time.
0 commit comments