Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: single breadcrumb item display separator #88

Merged
merged 7 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/layouts/default/header/components/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<template>
<a-breadcrumb class="!ml-2">
<a-breadcrumb-item v-for="(item,index) in routes" :key="index">
{{ item.meta.title }}
{{ item.name && item.meta.title }}
likui628 marked this conversation as resolved.
Show resolved Hide resolved
</a-breadcrumb-item>
</a-breadcrumb>
</template>

<script setup lang="ts">
import type { RouteLocationMatched } from 'vue-router'

const route = useRoute()
const router = useRouter()
const routes = ref(route.matched)
const routes = ref<RouteLocationMatched[]>([])

router.afterEach((to) => {
routes.value = to.matched
watchEffect(() => {
routes.value = route.matched.filter(item => !item.meta?.hideBreadcrumb)
})
</script>
8 changes: 6 additions & 2 deletions src/router/routes/modules/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ const route: RouteRecordRaw = {
component: DefaultLayout,
redirect: '/about',
meta: {
title: '关于',
icon: SettingOutlined,
single: true,
sort: 4
title: '关于',
sort: 4,
hideBreadcrumb: true
},
children: [
{
path: '',
name: 'about-page',
meta: {
title: '关于'
},
component: () => import('~/views/about/index.vue')
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes/plugins/dynamicRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouteStore } from '~/stores'
type RouteModule = GetArrayItemType<RouteModuleList>

function sortBySortKey(routerModuleList: RouteModuleList | RouteModule['children']) {
return routerModuleList!.sort((a: RouteModule, b: RouteModule) => a.meta!.sort - b.meta!.sort)
return routerModuleList!.sort((a: RouteModule, b: RouteModule) => (a.meta?.sort || Number.MAX_VALUE) - (b.meta?.sort || Number.MAX_VALUE))
}

function sortRoutesBySortKey(routerModuleList: RouteModuleList) {
Expand Down
4 changes: 3 additions & 1 deletion types/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ declare module 'vue-router' {
// 标题
title: string
// 排序索引
sort: number
sort?: number
// 是否隐藏菜单
isHide?: boolean
// icon,目前仅支持引入 antdv 中的 icon 组件
icon?: FunctionalComponent
// 是否是单独的菜单
single?: boolean
// 是否隐藏面包屑
hideBreadcrumb?: boolean
likui628 marked this conversation as resolved.
Show resolved Hide resolved
// 路由携带参数
routeParams?: RouteLocationNormalized['params']
routeQuery?: RouteLocationNormalized['query']
Expand Down