Skip to content

Commit

Permalink
docs: add inline documentation for Link props (#40855)
Browse files Browse the repository at this point in the history
## Example

**Instead of:**

<img width="674" alt="Screenshot 2022-09-23 at 21 25 58"
src="https://user-images.githubusercontent.com/1265681/192042744-6f1163e2-32af-49a0-bfba-385e5a7bad71.png">


**we should show:**

<img width="890" alt="Screenshot 2022-09-23 at 19 37 21"
src="https://user-images.githubusercontent.com/1265681/192042552-29e6a35a-49fc-4be1-89bf-edaa7b2f6dd9.png">

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

## Further Links

- https://tsdoc.org/

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
HaNdTriX and ijjk committed Sep 27, 2022
1 parent f53f581 commit a283b7b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions packages/next/client/link.tsx
Expand Up @@ -27,14 +27,60 @@ type OptionalKeys<T> = {
}[keyof T]

type InternalLinkProps = {
/**
* The path or URL to navigate to. It can also be an object.
*
* @example https://nextjs.org/docs/api-reference/next/link#with-url-object
*/
href: Url
/**
* Optional decorator for the path that will be shown in the browser URL bar. Before Next.js 9.5.3 this was used for dynamic routes, check our [previous docs](https://nextjs.org/docs/tag/v9.5.2/api-reference/next/link#dynamic-routes) to see how it worked. Note: when this path differs from the one provided in `href` the previous `href`/`as` behavior is used as shown in the [previous docs](https://nextjs.org/docs/tag/v9.5.2/api-reference/next/link#dynamic-routes).
*/
as?: Url
/**
* Replace the current `history` state instead of adding a new url into the stack.
*
* @defaultValue `false`
*/
replace?: boolean
/**
* Whether to override the default scroll behavior
*
* @example https://nextjs.org/docs/api-reference/next/link#disable-scrolling-to-the-top-of-the-page
*
* @defaultValue `true`
*/
scroll?: boolean
/**
* Update the path of the current page without rerunning [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md), [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md) or [`getInitialProps`](/docs/api-reference/data-fetching/get-initial-props.md).
*
* @defaultValue `false`
*/
shallow?: boolean
/**
* Forces `Link` to send the `href` property to its child.
*
* @defaultValue `false`
*/
passHref?: boolean
/**
* Prefetch the page in the background.
* Any `<Link />` that is in the viewport (initially or through scroll) will be preloaded.
* Prefetch can be disabled by passing `prefetch={false}`. When `prefetch` is set to `false`, prefetching will still occur on hover. Pages using [Static Generation](/docs/basic-features/data-fetching/get-static-props.md) will preload `JSON` files with the data for faster page transitions. Prefetching is only enabled in production.
*
* @defaultValue `true`
*/
prefetch?: boolean
/**
* The active locale is automatically prepended. `locale` allows for providing a different locale.
* When `false` `href` has to include the locale as the default behavior is disabled.
*/
locale?: string | false
/**
* Enable legacy link behaviour.
* @defaultValue `true`
* @see https://github.com/vercel/next.js/commit/489e65ed98544e69b0afd7e0cfc3f9f6c2b803b7
*/
legacyBehavior?: boolean
// e: any because as it would otherwise overlap with existing types
/**
Expand Down Expand Up @@ -153,6 +199,9 @@ type LinkPropsReal = React.PropsWithChildren<
LinkProps
>

/**
* React Component that enables client-side transitions between routes.
*/
const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
function LinkComponent(props, forwardedRef) {
if (process.env.NODE_ENV !== 'production') {
Expand Down

0 comments on commit a283b7b

Please sign in to comment.