Skip to content

Open source personal finance application

refactor: replace router.push with NuxtLink for navigation

Ilya Komichevcaf6f954153d
diff --git a/app/components/app/Onboarding.vue b/app/components/app/Onboarding.vue
index 18b716f2..a845087b 100644
--- a/app/components/app/Onboarding.vue
+++ b/app/components/app/Onboarding.vue
@@ -4,7 +4,6 @@ import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
const { t } = useI18n()
-const router = useRouter()
const walletsStore = useWalletsStore()
const categoriesStore = useCategoriesStore()
const trnsFormStore = useTrnsFormStore()
@@ -33,18 +32,18 @@ const introText = computed(() => {
<UButton
v-if="!walletsStore.hasItems"
+ to="/wallets/new?onboarding"
size="xl"
class="min-w-52 justify-center rounded-full px-8 py-3"
- @click="router.push('/wallets/new?onboarding')"
>
{{ t('onboarding.actionWallet') }}
</UButton>
<UButton
v-else-if="!categoriesStore.hasItems"
+ to="/categories/new?onboarding"
size="xl"
class="min-w-52 justify-center rounded-full px-8 py-3"
- @click="router.push('/categories/new?onboarding')"
>
{{ t('onboarding.actionCategory') }}
</UButton>
diff --git a/app/components/categories/Header.vue b/app/components/categories/Header.vue
index 6ca9a635..d6379980 100644
--- a/app/components/categories/Header.vue
+++ b/app/components/categories/Header.vue
@@ -5,12 +5,6 @@ const props = defineProps<{
category: CategoryItem
parentCategory?: CategoryItem
}>()
-
-const router = useRouter()
-
-function onParentClick() {
- router.push(`/categories/${props.category.parentId}`)
-}
</script>
<template>
@@ -38,12 +32,12 @@ function onParentClick() {
•
</div>
- <div
- class="flex items-center gap-2 rounded-lg px-3 py-1 hover:bg-(--item-5)"
- @click="onParentClick"
+ <NuxtLink
+ :to="`/categories/${props.category.parentId}`"
+ class="flex items-center gap-2 rounded-lg px-3 py-1 no-underline text-inherit hover:bg-(--item-5)"
>
{{ props.parentCategory.name }}
- </div>
+ </NuxtLink>
</div>
</div>
</UiHeaderTitle>
diff --git a/app/components/categories/Item.vue b/app/components/categories/Item.vue
index a0d79c56..4ccd201b 100644
--- a/app/components/categories/Item.vue
+++ b/app/components/categories/Item.vue
@@ -11,6 +11,7 @@ export type CategoryItemProps = {
insideClasses?: string
isShowParent?: boolean
lineWidth?: number
+ to?: string
}
const props = defineProps<CategoryItemProps>()
@@ -32,6 +33,7 @@ const emit = defineEmits<{
:insideClasses="props.insideClasses"
:isShowParent="props.isShowParent"
:lineWidth="props.lineWidth"
+ :to="props.to"
@click="emit('click', $event)"
@filter="emit('filter', $event)"
/>
diff --git a/app/components/categories/ItemBody.vue b/app/components/categories/ItemBody.vue
index 2a9d8d72..a3eb90f8 100644
--- a/app/components/categories/ItemBody.vue
+++ b/app/components/categories/ItemBody.vue
@@ -12,6 +12,7 @@ const props = defineProps<{
insideClasses?: string
isShowParent?: boolean
lineWidth?: number
+ to?: string
}>()
const emit = defineEmits<{
@@ -32,6 +33,7 @@ const parentCategory = computed(() => categoriesStore.items[props.category?.pare
:class="props.class"
:lineWidth="props.lineWidth"
:insideClasses="`min-h-[46px] ${props.insideClasses}`"
+ :to="props.to"
@click="(e: Event) => emit('click', e)"
>
<template #leftIcon>
diff --git a/app/components/categories/List.vue b/app/components/categories/List.vue
index 03358d3c..48686a62 100644
--- a/app/components/categories/List.vue
+++ b/app/components/categories/List.vue
@@ -8,6 +8,7 @@ const props = defineProps<{
activeItemId?: string | 0 | false | null
categoriesItemProps?: Partial<CategoryItemProps>
getContextMenuItems?: (categoryId: CategoryId) => any[][] | undefined
+ getTo?: (categoryId: CategoryId) => string
ids: CategoryId[]
insideClasses?: string
}>()
@@ -29,6 +30,7 @@ const categoriesStore = useCategoriesStore()
:categoryId="categoryId"
:contextMenuItems="props.getContextMenuItems?.(categoryId)"
:insideClasses="props.insideClasses"
+ :to="props.getTo?.(categoryId)"
:lineWidth="1"
v-bind="categoriesItemProps"
@click="emit('click', categoryId)"
diff --git a/app/components/categories/page/List.vue b/app/components/categories/page/List.vue
index 879e1043..ba406ff9 100644
--- a/app/components/categories/page/List.vue
+++ b/app/components/categories/page/List.vue
@@ -9,7 +9,6 @@ import { useTrnsStore } from '~/components/trns/useTrnsStore'
import { showErrorToast, showSuccessToast } from '~/composables/useStoreSync'
const { t } = useI18n()
-const router = useRouter()
const categoriesStore = useCategoriesStore()
const trnsStore = useTrnsStore()
@@ -85,9 +84,11 @@ const { getCategoryContextMenuItems } = useCategoryContextMenu({
/>
</UiActionButton>
- <UiActionButton :ariaLabel="$t('categories.new')" @click="router.push('/categories/new')">
- <Icon name="lucide:plus" size="24" />
- </UiActionButton>
+ <NuxtLink to="/categories/new">
+ <UiActionButton :ariaLabel="$t('categories.new')">
+ <Icon name="lucide:plus" size="24" />
+ </UiActionButton>
+ </NuxtLink>
</template>
</UiHeader>
@@ -99,12 +100,11 @@ const { getCategoryContextMenuItems } = useCategoryContextMenu({
<UiTitleSection class="pb-4">
{{ t('categories.new') }}
</UiTitleSection>
- <UiButtonAccent
- rounded
- @click="router.push('/categories/new')"
- >
- {{ t('categories.new') }}
- </UiButtonAccent>
+ <NuxtLink to="/categories/new">
+ <UiButtonAccent rounded>
+ {{ t('categories.new') }}
+ </UiButtonAccent>
+ </NuxtLink>
</div>
<!-- List -->
@@ -123,7 +123,7 @@ const { getCategoryContextMenuItems } = useCategoryContextMenu({
}"
:getContextMenuItems="getCategoryContextMenuItems"
:insideClasses="categoriesView === 'grid' ? 'bg-item-2' : ''"
- @click="(categoryId: CategoryId) => router.push(`/categories/${categoryId}`)"
+ :getTo="(categoryId: CategoryId) => `/categories/${categoryId}`"
/>
</div>
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vue
index ff407935..f2793acd 100644
--- a/app/components/categories/page/id/Index.vue
+++ b/app/components/categories/page/id/Index.vue
@@ -193,7 +193,7 @@ const categoriesIds = computed(() => categoriesStore.getChildrenIds(categoryId.v
:categoriesItemProps="{
class: 'group',
}"
- @click="(categoryId: CategoryId) => router.push(`/categories/${categoryId}`)"
+ :getTo="(categoryId: CategoryId) => `/categories/${categoryId}`"
/>
</div>
diff --git a/app/components/layout/Sidebar.vue b/app/components/layout/Sidebar.vue
index 956e545d..8f63cd08 100644
--- a/app/components/layout/Sidebar.vue
+++ b/app/components/layout/Sidebar.vue
@@ -13,7 +13,6 @@ const props = defineProps<{
const emit = defineEmits(['toggleSidebar'])
const route = useRoute()
-const router = useRouter()
const userStore = useUserStore()
const { isDemo } = useDemo()
const { t } = useI18n()
@@ -94,19 +93,18 @@ const { getWalletContextMenuItems } = useWalletContextMenu()
isShowCreditLimit
isShowRate
isShowIcon
- @click="() => walletId === route.params.id ? router.push('/dashboard') : router.push(`/wallets/${walletId}`)"
+ :to="walletId === route.params.id ? '/dashboard' : `/wallets/${walletId}`"
/>
<div
v-if="walletsIdsSorted.length === 0"
class="flex-center flex-col py-4"
>
- <UiButtonAccent
- rounded
- @click="router.push('/wallets/new')"
- >
- {{ t('wallets.new') }}
- </UiButtonAccent>
+ <NuxtLink to="/wallets/new">
+ <UiButtonAccent rounded>
+ {{ t('wallets.new') }}
+ </UiButtonAccent>
+ </NuxtLink>
</div>
</template>
</WalletsList>
diff --git a/app/components/ui/Element.vue b/app/components/ui/Element.vue
index 2b33aa2b..ca714c09 100644
--- a/app/components/ui/Element.vue
+++ b/app/components/ui/Element.vue
@@ -3,6 +3,7 @@ const props = defineProps<{
insideClasses?: string
isActive?: boolean
lineWidth?: number
+ to?: string
}>()
const emit = defineEmits<{
@@ -19,7 +20,12 @@ const elementClasses = computed(() => cn(
</script>
<template>
- <div @click="(e: Event) => emit('click', e)">
+ <component
+ :is="props.to ? resolveComponent('NuxtLink') : 'div'"
+ :to="props.to"
+ :class="{ uiElementLink: props.to }"
+ @click="(e: Event) => emit('click', e)"
+ >
<div :class="elementClasses">
<div
v-if="slots.leftIcon"
@@ -43,12 +49,16 @@ const elementClasses = computed(() => cn(
}"
class="mx-2 h-px bg-(--item-5)"
/>
- </div>
+ </component>
</template>
<style>
@reference '../../assets/css/main.css';
+a.uiElementLink {
+ @apply no-underline text-inherit;
+}
+
[data-state='open'] > .uiElement {
@apply !bg-item-4;
}
diff --git a/app/components/wallets/Item.vue b/app/components/wallets/Item.vue
index 292c510a..44fa48e3 100644
--- a/app/components/wallets/Item.vue
+++ b/app/components/wallets/Item.vue
@@ -12,6 +12,7 @@ const props = defineProps<{
isShowRate?: boolean
isSort?: boolean
lineWidth?: number
+ to?: string
wallet: WalletItemComputed
walletId: WalletId
}>()
@@ -33,6 +34,7 @@ const emit = defineEmits<{
:isShowRate="props.isShowRate"
:isSort="props.isSort"
:lineWidth="props.lineWidth"
+ :to="props.to"
:wallet="props.wallet"
:walletId="props.walletId"
@click="emit('click', $event)"
diff --git a/app/components/wallets/ItemBody.vue b/app/components/wallets/ItemBody.vue
index e0e8418e..b754f4fc 100644
--- a/app/components/wallets/ItemBody.vue
+++ b/app/components/wallets/ItemBody.vue
@@ -17,6 +17,7 @@ const props = defineProps<{
isShowRate?: boolean
isSort?: boolean
lineWidth?: number
+ to?: string
wallet: WalletItemComputed
walletId: WalletId
}>()
@@ -74,6 +75,7 @@ if (!props.isSort) {
:isActive="activeItemId === props.walletId"
:insideClasses="`${props.insideClasses ?? ''} min-h-[46px]`"
:lineWidth="props.lineWidth"
+ :to="props.to"
:class="classes"
@click="emit('click', props.walletId)"
>
diff --git a/app/components/wallets/page/List.vue b/app/components/wallets/page/List.vue
index 7c187798..de7fcba2 100644
--- a/app/components/wallets/page/List.vue
+++ b/app/components/wallets/page/List.vue
@@ -12,7 +12,6 @@ import { useWalletsGrouping } from '~/components/wallets/useWalletsGrouping'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
const { t } = useI18n()
-const router = useRouter()
useSeoMeta({
ogTitle: t('wallets.name'),
@@ -70,9 +69,11 @@ function hasGroups(groups: Record<string, unknown> | undefined) {
<UiHeaderTitle>{{ t('wallets.name') }}</UiHeaderTitle>
<template #actions>
- <UiActionButton :ariaLabel="$t('wallets.new')" @click="router.push('/wallets/new')">
- <Icon name="lucide:plus" size="24" />
- </UiActionButton>
+ <NuxtLink to="/wallets/new">
+ <UiActionButton :ariaLabel="$t('wallets.new')">
+ <Icon name="lucide:plus" size="24" />
+ </UiActionButton>
+ </NuxtLink>
<BottomSheetOrDropdown
v-if="walletsStore.sortedIds.length > 1"
@@ -109,12 +110,11 @@ function hasGroups(groups: Record<string, unknown> | undefined) {
<UiTitleSection class="pb-4">
{{ t('wallets.new') }}
</UiTitleSection>
- <UiButtonAccent
- rounded
- @click="router.push('/wallets/new')"
- >
- {{ t('wallets.new') }}
- </UiButtonAccent>
+ <NuxtLink to="/wallets/new">
+ <UiButtonAccent rounded>
+ {{ t('wallets.new') }}
+ </UiButtonAccent>
+ </NuxtLink>
</div>
<!-- Content -->
diff --git a/app/components/wallets/page/ListItem.vue b/app/components/wallets/page/ListItem.vue
index 6d42d0d6..7de6c85e 100644
--- a/app/components/wallets/page/ListItem.vue
+++ b/app/components/wallets/page/ListItem.vue
@@ -12,7 +12,6 @@ const emit = defineEmits<{
delete: [walletId: WalletId]
}>()
-const router = useRouter()
const walletsStore = useWalletsStore()
const { getWalletContextMenuItems } = useWalletContextMenu({
@@ -31,6 +30,6 @@ const { getWalletContextMenuItems } = useWalletContextMenu({
isShowCreditLimit
isShowIcon
isShowRate
- @click="router.push(`/wallets/${props.walletId}`)"
+ :to="`/wallets/${props.walletId}`"
/>
</template>
diff --git a/app/layouts/error.vue b/app/layouts/error.vue
index 9e230d76..9a5c5dd5 100644
--- a/app/layouts/error.vue
+++ b/app/layouts/error.vue
@@ -15,9 +15,9 @@ if (Object.keys(route.query).length > 0)
<div class="p-4">
<h1>{{ t('actionError.title') }}</h1>
<pre>{{ error }}</pre>
- <h1 @click="router.push('/')">
- {{ t('actionError.goHome') }}
- </h1>
+ <NuxtLink to="/" class="text-inherit">
+ <h1>{{ t('actionError.goHome') }}</h1>
+ </NuxtLink>
<slot />
</div>
</template>