From 64579f7d74944dc01fdbab4ac8fdd917e9ded4d6 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Wed, 23 Feb 2022 17:46:52 +0100 Subject: [PATCH] fix breadcrumb home link bug with useHomePageRoute() --- .../src/index.d.ts | 2 +- .../src/theme/DocBreadcrumbs/index.tsx | 9 ++- packages/docusaurus-theme-common/package.json | 2 +- packages/docusaurus-theme-common/src/index.ts | 2 + .../src/utils/__tests__/routesUtils.test.ts | 73 +++++++++++++++++++ .../src/utils/routesUtils.ts | 39 ++++++++++ 6 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 packages/docusaurus-theme-common/src/utils/__tests__/routesUtils.test.ts create mode 100644 packages/docusaurus-theme-common/src/utils/routesUtils.ts diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 7292518fc3b9..0ca795ee13b4 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -37,7 +37,7 @@ declare module '@generated/registry' { declare module '@generated/routes' { import type {RouteConfig} from 'react-router-config'; - type Route = { + export type Route = { readonly path: string; readonly component: RouteConfig['component']; readonly exact?: boolean; diff --git a/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx index 8eecbe54170a..f912aac438a4 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx @@ -6,7 +6,11 @@ */ import React, {type ReactNode} from 'react'; -import {ThemeClassNames, useSidebarBreadcrumbs} from '@docusaurus/theme-common'; +import { + ThemeClassNames, + useSidebarBreadcrumbs, + useHomePageRoute, +} from '@docusaurus/theme-common'; import styles from './styles.module.css'; import clsx from 'clsx'; import Link from '@docusaurus/Link'; @@ -59,6 +63,7 @@ function HomeBreadcrumbItem() { export default function DocBreadcrumbs(): JSX.Element | null { const breadcrumbs = useSidebarBreadcrumbs(); + const homePageRoute = useHomePageRoute(); if (!breadcrumbs) { return null; @@ -72,7 +77,7 @@ export default function DocBreadcrumbs(): JSX.Element | null { )} aria-label="breadcrumbs">