fumadocs-core
Version:
The React.js library for building a documentation website
34 lines (31 loc) • 1 kB
JavaScript
'use client';
import { useParams } from "./framework/index.js";
import Link from "./link.js";
import { forwardRef, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
//#region src/dynamic-link.tsx
/**
* Extends the default `Link` component
*
* It supports dynamic hrefs, which means you can use `/[lang]/my-page` with `dynamicHrefs` enabled
*/
const DynamicLink = forwardRef(({ href, ...props }, ref) => {
const params = useParams();
return /* @__PURE__ */ jsx(Link, {
ref,
href: useMemo(() => {
return href?.replace(/\[.*]/, (key) => {
const mappedKey = key.slice(1, -1);
const value = mappedKey in params ? params[mappedKey] : void 0;
if (!value) return "";
return typeof value === "string" ? value : value.join("/");
});
}, [params, href]),
...props
});
});
DynamicLink.displayName = "DynamicLink";
var dynamic_link_default = DynamicLink;
//#endregion
export { DynamicLink, dynamic_link_default as default };
//# sourceMappingURL=dynamic-link.js.map