Skip to content

Commit 2f3a978

Browse files
committed
chore(ux): consistent back navigation
1 parent 16b012a commit 2f3a978

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

app/composables/useCanGoBack.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function useCanGoBack() {
2+
const canGoBack = ref(false)
3+
4+
if (import.meta.client) {
5+
const router = useRouter()
6+
canGoBack.value = router.options.history.state.back !== null
7+
}
8+
9+
return canGoBack
10+
}

app/pages/about.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
const router = useRouter()
3+
const canGoBack = useCanGoBack()
34
45
interface GitHubContributor {
56
login: string
@@ -53,7 +54,7 @@ const { data: contributors, status: contributorsStatus } = useFetch<GitHubContri
5354
type="button"
5455
class="inline-flex items-center gap-2 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
5556
@click="router.back()"
56-
v-show="router.options.history.state.back !== null"
57+
v-if="canGoBack"
5758
>
5859
<span class="i-carbon:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
5960
<span class="hidden sm:inline">{{ $t('nav.back') }}</span>

app/pages/compare.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ definePageMeta({
77
})
88
99
const router = useRouter()
10+
const canGoBack = useCanGoBack()
1011
1112
// Sync packages with URL query param (stable ref - doesn't change on other query changes)
1213
const packagesParam = useRouteQuery<string>('packages', '', { mode: 'replace' })
@@ -118,7 +119,7 @@ useSeoMeta({
118119
type="button"
119120
class="inline-flex items-center gap-2 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
120121
@click="router.back()"
121-
v-show="router.options.history.state.back !== null"
122+
v-if="canGoBack"
122123
>
123124
<span class="i-carbon:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
124125
<span class="hidden sm:inline">{{ $t('nav.back') }}</span>

app/pages/privacy.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defineOgImageComponent('Default', {
1414
})
1515
1616
const router = useRouter()
17+
const canGoBack = useCanGoBack()
1718
const buildInfo = useAppConfig().buildInfo
1819
const { locale } = useI18n()
1920
</script>
@@ -30,7 +31,7 @@ const { locale } = useI18n()
3031
type="button"
3132
class="inline-flex items-center gap-2 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
3233
@click="router.back()"
33-
v-show="router.options.history.state.back !== null"
34+
v-if="canGoBack"
3435
>
3536
<span class="i-carbon:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
3637
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>

app/pages/settings.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
const router = useRouter()
3+
const canGoBack = useCanGoBack()
34
const { settings } = useSettings()
45
const { locale, locales, setLocale: setNuxti18nLocale } = useI18n()
56
const colorMode = useColorMode()
@@ -52,7 +53,7 @@ const setLocale: typeof setNuxti18nLocale = locale => {
5253
type="button"
5354
class="inline-flex items-center gap-2 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0 p-1.5 -mx-1.5"
5455
@click="router.back()"
55-
v-show="router.options.history.state.back !== null"
56+
v-if="canGoBack"
5657
>
5758
<span class="i-carbon:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
5859
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>

0 commit comments

Comments
 (0)