import { Link } from '@tanstack/react-router' import { forwardRef, type ComponentProps, type ComponentPropsWithoutRef } from 'react' import { isAbsoluteUrl, splitInternalUrl } from '@/lib/internal-url' export interface DynamicLinkProps extends Omit, 'href'>, Pick, 'replace' | 'preload'> { href: string } /** * Link wrapper for dynamic/untyped URL strings (e.g. paths that may include * query strings, hashes, `BASE_PATH`, or external origins). Splits the URL * via `splitInternalUrl` and renders a plain `` for external URLs (or * same-origin URLs outside the app's basePath) and a TanStack `` for * internal paths. * * Prefer `@tanstack/react-router`'s `` directly when the target is a * known internal route so params and search stay type-checked. */ export const DynamicLink = forwardRef(function DynamicLink( { href, replace, preload, children, ...props }, ref ) { const { to, search, hash } = splitInternalUrl(href) if (isAbsoluteUrl(to)) { return ( {children} ) } return ( {children} ) })