fix: Add `route.name` null check (#132)

This commit is contained in:
CharleeWa 2024-11-10 20:20:00 +08:00
parent d750a2afb9
commit 0658a01342
3 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,6 @@
<script setup lang="ts">
import { routeWhiteList } from '@/config/routes'
const route = useRoute()
const router = useRouter()
@ -18,9 +20,7 @@ const title = computed(() => {
return route.meta.i18n ? t(route.meta.i18n) : (route.meta.title || '')
})
const routeWhiteList = ['home', 'profile']
const showLeftArrow = computed(() => routeWhiteList.includes(route.name))
const showLeftArrow = computed(() => route.name && routeWhiteList.includes(route.name))
</script>
<template>

View File

@ -1,11 +1,11 @@
<script setup lang="ts">
import { routeWhiteList } from '@/config/routes'
const { t } = useI18n()
const active = ref(0)
const route = useRoute()
const routeWhiteList = ['home', 'profile']
const show = computed(() => routeWhiteList.includes(route.name))
const show = computed(() => route.name && routeWhiteList.includes(route.name))
</script>
<template>

5
src/config/routes.ts Normal file
View File

@ -0,0 +1,5 @@
// 定义导航栏和标签栏可见的路由白名单
export const routeWhiteList: readonly string[] = [
'home', // 首页
'profile', // 个人中心
]