Skip to content

Commit ad8e212

Browse files
authored
chore: fix navigation for back (#276)
1 parent 484a888 commit ad8e212

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

app/pages/settings.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff 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
*/
1515
function 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
2725
function goBack() {

0 commit comments

Comments
 (0)