docs: fix base path not added to hash links (#10235)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-11-22 18:42:49 +02:00
1 parent 97ef3a5337
commit 78e68a0bb6
4 files changed
+41 -30

No files matched your search

@@ -1,10 +1,9 @@
"use client"
import clsx from "clsx"
import React, { useMemo } from "react"
import React from "react"
import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"
import { usePathname } from "next/navigation"
import { useHeadingUrl } from "../../.."
type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
id?: string
@@ -12,16 +11,9 @@ type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
}
export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
const { isBrowser } = useIsBrowser()
const pathname = usePathname()
const copyText = useMemo(() => {
const hash = `#${props.id}`
if (!isBrowser) {
return hash
}
return `${window.location.origin}${pathname}${hash}`
}, [props.id, isBrowser, pathname])
const copyText = useHeadingUrl({
id: props.id || "",
})
return (
<h2
className={clsx(