From 75cb85bc8bf97f46d9536d0e6a583ef5ba53d16a Mon Sep 17 00:00:00 2001 From: "chen.home" <1147347984@qq.com> Date: Sat, 27 Aug 2022 23:03:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(breadcrumb):=20=E4=BF=AE=E5=A4=8D=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 8 ++++---- src/layouts/components/header/Breadcrumb.vue | 5 ++++- src/store/modules/route.ts | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 67bbe72..987824e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -47,10 +47,10 @@ module.exports = { ], rules: { // TSESLint docs https://typescript-eslint.io/rules/ - // 'no-var': 'error', // 禁止使用var - // 'no-unused-vars': 'off', // 允许声明不使用的值 - // 'no-console': 'off', // 允许出现console - // 'no-debugger': 'off', // 关闭debugger警告 + 'no-var': 'error', // 禁止使用var + 'no-unused-vars': 'off', // 允许声明不使用的值 + 'no-console': 'off', // 允许出现console + 'no-debugger': 'off', // 关闭debugger警告 'vue/multi-word-component-names': 0, // 关闭文件名多单词 // 'import/no-unresolved': ['error', { ignore: ['~icons/*'] }], "@typescript-eslint/no-explicit-any": ["off"], // 允许使用any diff --git a/src/layouts/components/header/Breadcrumb.vue b/src/layouts/components/header/Breadcrumb.vue index 6b43493..b1c091d 100644 --- a/src/layouts/components/header/Breadcrumb.vue +++ b/src/layouts/components/header/Breadcrumb.vue @@ -17,7 +17,10 @@ const router = useRouter(); const routeStore = useRouteStore(); const { routerPush } = useAppRouter(); const routes = computed(() => { - return routeStore.createBreadcrumbFromRoutes(router.currentRoute.value.name as string, routeStore.userRoutes); + return routeStore.createBreadcrumbFromRoutes( + (router.currentRoute.value.name as string) || '/', + routeStore.userRoutes, + ); }); diff --git a/src/store/modules/route.ts b/src/store/modules/route.ts index fd7d0a3..9cc0a9c 100644 --- a/src/store/modules/route.ts +++ b/src/store/modules/route.ts @@ -33,7 +33,7 @@ export const useRouteStore = defineStore('route-store', { router.removeRoute('appRoot'); }, /* 根据当前路由的name生成面包屑数据 */ - createBreadcrumbFromRoutes(routeName = '/', userRoutes: AppRoute.Route[]) { + createBreadcrumbFromRoutes(routeName: string, userRoutes: AppRoute.Route[]) { const path: AppRoute.Route[] = []; // 筛选所有包含目标的各级路由组合成一维数组 const getPathfromRoutes = (routeName: string, userRoutes: AppRoute.Route[]) => {