(
props: LinkProps & {
children: React.ReactNode
ref: React.Ref<HTMLAnchorElement>
}
)
| 335 | * @see https://nextjs.org/docs/app/api-reference/components/link |
| 336 | */ |
| 337 | export default function LinkComponent( |
| 338 | props: LinkProps & { |
| 339 | children: React.ReactNode |
| 340 | ref: React.Ref<HTMLAnchorElement> |
| 341 | } |
| 342 | ) { |
| 343 | const [linkStatus, setOptimisticLinkStatus] = useOptimistic(IDLE_LINK_STATUS) |
| 344 | |
| 345 | let children: React.ReactNode |
| 346 | |
| 347 | const linkInstanceRef = useRef<LinkInstance | null>(null) |
| 348 | |
| 349 | const { |
| 350 | href: hrefProp, |
| 351 | as: asProp, |
| 352 | children: childrenProp, |
| 353 | prefetch: prefetchProp = null, |
| 354 | passHref, |
| 355 | replace, |
| 356 | shallow, |
| 357 | scroll, |
| 358 | onClick, |
| 359 | onMouseEnter: onMouseEnterProp, |
| 360 | onTouchStart: onTouchStartProp, |
| 361 | legacyBehavior = false, |
| 362 | onNavigate, |
| 363 | transitionTypes, |
| 364 | ref: forwardedRef, |
| 365 | unstable_dynamicOnHover, |
| 366 | ...restProps |
| 367 | } = props |
| 368 | |
| 369 | children = childrenProp |
| 370 | |
| 371 | if ( |
| 372 | legacyBehavior && |
| 373 | (typeof children === 'string' || typeof children === 'number') |
| 374 | ) { |
| 375 | children = <a>{children}</a> |
| 376 | } |
| 377 | |
| 378 | const router = React.useContext(AppRouterContext) |
| 379 | |
| 380 | const prefetchEnabled = prefetchProp !== false |
| 381 | |
| 382 | const fetchStrategy = |
| 383 | prefetchProp !== false |
| 384 | ? getFetchStrategyFromPrefetchProp(prefetchProp) |
| 385 | : // TODO: it makes no sense to assign a fetchStrategy when prefetching is disabled. |
| 386 | FetchStrategy.PPR |
| 387 | |
| 388 | if (process.env.NODE_ENV !== 'production') { |
| 389 | function createPropError(args: { |
| 390 | key: string |
| 391 | expected: string |
| 392 | actual: string |
| 393 | }) { |
| 394 | return new Error( |
nothing calls this directly
no test coverage detected