Skip to content

Commit f488bc2

Browse files
[sitecore-jss-nextjs] Update Link.tsx to support next/link's prefetch property (#2039)
1 parent 0a90a40 commit f488bc2

File tree

1 file changed

+9
-1
lines changed
  • packages/sitecore-jss-nextjs/src/components

1 file changed

+9
-1
lines changed

packages/sitecore-jss-nextjs/src/components/Link.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { forwardRef } from 'react';
22
import PropTypes from 'prop-types';
33
import NextLink from 'next/link';
4+
import { LinkProps as NextLinkProps } from 'next/link';
45
import {
56
Link as ReactLink,
67
LinkFieldValue,
@@ -15,6 +16,11 @@ export type LinkProps = ReactLinkProps & {
1516
* @default /^\//g
1617
*/
1718
internalLinkMatcher?: RegExp;
19+
20+
/**
21+
* Support next/link's prefetch prop.
22+
*/
23+
prefetch?: NextLinkProps['prefetch'];
1824
};
1925

2026
/**
@@ -68,6 +74,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
6874
title={value.title}
6975
target={value.target}
7076
className={value.class}
77+
prefetch={props.prefetch}
7178
{...htmlLinkProps}
7279
ref={ref}
7380
>
@@ -78,9 +85,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
7885
}
7986
}
8087

81-
// prevent passing internalLinkMatcher as it is an invalid DOM element prop
88+
// prevent passing internalLinkMatcher or prefetch as it is an invalid DOM element prop
8289
const reactLinkProps = { ...props };
8390
delete reactLinkProps.internalLinkMatcher;
91+
delete reactLinkProps.prefetch;
8492

8593
return <ReactLink {...reactLinkProps} ref={ref} />;
8694
}

0 commit comments

Comments
 (0)