Skip to content

Commit 0658a01

Browse files
committed
fix: Add route.name null check (#132)
1 parent d750a2a commit 0658a01

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/components/NavBar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { routeWhiteList } from '@/config/routes'
3+
24
const route = useRoute()
35
const router = useRouter()
46
@@ -18,9 +20,7 @@ const title = computed(() => {
1820
return route.meta.i18n ? t(route.meta.i18n) : (route.meta.title || '')
1921
})
2022
21-
const routeWhiteList = ['home', 'profile']
22-
23-
const showLeftArrow = computed(() => routeWhiteList.includes(route.name))
23+
const showLeftArrow = computed(() => route.name && routeWhiteList.includes(route.name))
2424
</script>
2525

2626
<template>

src/components/TabBar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2+
import { routeWhiteList } from '@/config/routes'
3+
24
const { t } = useI18n()
35
const active = ref(0)
46
const route = useRoute()
57
6-
const routeWhiteList = ['home', 'profile']
7-
8-
const show = computed(() => routeWhiteList.includes(route.name))
8+
const show = computed(() => route.name && routeWhiteList.includes(route.name))
99
</script>
1010

1111
<template>

src/config/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// 定义导航栏和标签栏可见的路由白名单
2+
export const routeWhiteList: readonly string[] = [
3+
'home', // 首页
4+
'profile', // 个人中心
5+
]

0 commit comments

Comments
 (0)