Skip to content

Commit bc1dc0b

Browse files
committedSep 8, 2024·
fix(useBreadcrumbItems): avoid route path becoming label
Fixes #311
1 parent 9f875b1 commit bc1dc0b

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed
 

‎src/runtime/nuxt/composables/polyfills.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export function defineWebPage() {}
88
export function useI18n() {
99
const siteConfig = useSiteConfig()
1010
return {
11-
t: (_: string, fallback: string) => fallback,
11+
// eslint-disable-next-line unused-imports/no-unused-vars
12+
t: (_: string, fallback: string, options: any) => fallback,
1213
te: (_: string) => false,
1314
strategy: 'no_prefix',
1415
defaultLocale: ref(siteConfig.defaultLocale || 'en'),

‎src/runtime/nuxt/composables/useBreadcrumbItems.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
defineBreadcrumb,
1212
toValue,
1313
useI18n,
14-
useRoute,
1514
useRouter,
1615
useSchemaOrg,
1716
useSiteConfig,
@@ -154,7 +153,7 @@ export function useBreadcrumbItems(options: BreadcrumbProps = {}) {
154153
const routeMeta = (route?.meta || {}) as RouteMeta & { title?: string, breadcrumbLabel: string }
155154
const routeName = route ? String(route.name || route.path) : (item.to === '/' ? 'index' : 'unknown')
156155
let [name] = routeName.split('___')
157-
if (name === 'unknown')
156+
if (name === 'unknown' || name.includes('/'))
158157
name = (item.to || '').split('/').pop() || '' // fallback to last path segment
159158
// merge with the route meta
160159
if (routeMeta.breadcrumb) {
@@ -167,14 +166,11 @@ export function useBreadcrumbItems(options: BreadcrumbProps = {}) {
167166
// @ts-expect-error untyped
168167
item.label = item.label || routeMeta.breadcrumbTitle || routeMeta.title
169168
if (typeof item.label === 'undefined') {
170-
// try use i18n
171-
// fetch from i18n
172-
// @ts-expect-error untyped
173-
item.label = item.label || i18n.t(`breadcrumb.items.${name}.label`, name === 'index' ? 'Home' : titleCase(name), { missingWarn: false })
174-
// @ts-expect-error untyped
175-
item.ariaLabel = item.ariaLabel || i18n.t(`breadcrumb.items.${name}.ariaLabel`, item.label, { missingWarn: false })
169+
item.label = i18n.t(`breadcrumb.items.${name}.label`, name === 'index' ? 'Home' : titleCase(name), { missingWarn: false })
170+
}
171+
if (typeof item.ariaLabel === 'undefined') {
172+
item.ariaLabel = i18n.t(`breadcrumb.items.${name}.ariaLabel`, item.label, { missingWarn: false }) || item.label
176173
}
177-
item.ariaLabel = item.ariaLabel || item.label
178174
// mark the current based on the options
179175
item.current = item.current || item.to === current
180176
if (toValue(options.hideCurrent) && item.current)

0 commit comments

Comments
 (0)
Please sign in to comment.