Skip to content

Commit

Permalink
[examples] Next.js examples v13 - links (mui#34970)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroSilenius authored and Daniel Rabe committed Nov 29, 2022
1 parent 2254b40 commit c0a420c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
25 changes: 23 additions & 2 deletions examples/nextjs-with-typescript/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ interface NextLinkComposedProps

export const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComposedProps>(
function NextLinkComposed(props, ref) {
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
const {
to,
linkAs,
replace,
scroll,
shallow,
prefetch,
legacyBehavior = true,
locale,
...other
} = props;

return (
<NextLink
Expand All @@ -29,6 +39,7 @@ export const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComp
shallow={shallow}
passHref
locale={locale}
legacyBehavior={legacyBehavior}
>
<Anchor ref={ref} {...other} />
</NextLink>
Expand All @@ -53,6 +64,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
as,
className: classNameProps,
href,
legacyBehavior,
linkAs: linkAsProp,
locale,
noLinkStyle,
Expand Down Expand Up @@ -82,7 +94,16 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
}

const linkAs = linkAsProp || as;
const nextjsProps = { to: href, linkAs, replace, scroll, shallow, prefetch, locale };
const nextjsProps = {
to: href,
linkAs,
replace,
scroll,
shallow,
prefetch,
legacyBehavior,
locale,
};

if (noLinkStyle) {
return <NextLinkComposed className={className} ref={ref} {...nextjsProps} {...other} />;
Expand Down
27 changes: 25 additions & 2 deletions examples/nextjs/src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ import { styled } from '@mui/material/styles';
const Anchor = styled('a')({});

export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props, ref) {
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
const {
to,
linkAs,
replace,
scroll,
shallow,
prefetch,
legacyBehavior = true,
locale,
...other
} = props;

return (
<NextLink
Expand All @@ -21,6 +31,7 @@ export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props
scroll={scroll}
shallow={shallow}
passHref
legacyBehavior={legacyBehavior}
locale={locale}
>
<Anchor ref={ref} {...other} />
Expand All @@ -30,6 +41,7 @@ export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props

NextLinkComposed.propTypes = {
href: PropTypes.any,
legacyBehavior: PropTypes.bool,
linkAs: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
locale: PropTypes.string,
passHref: PropTypes.bool,
Expand All @@ -48,6 +60,7 @@ const Link = React.forwardRef(function Link(props, ref) {
as,
className: classNameProps,
href,
legacyBehavior,
linkAs: linkAsProp,
locale,
noLinkStyle,
Expand Down Expand Up @@ -77,7 +90,16 @@ const Link = React.forwardRef(function Link(props, ref) {
}

const linkAs = linkAsProp || as;
const nextjsProps = { to: href, linkAs, replace, scroll, shallow, prefetch, locale };
const nextjsProps = {
to: href,
linkAs,
replace,
scroll,
shallow,
prefetch,
legacyBehavior,
locale,
};

if (noLinkStyle) {
return <NextLinkComposed className={className} ref={ref} {...nextjsProps} {...other} />;
Expand All @@ -99,6 +121,7 @@ Link.propTypes = {
as: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
className: PropTypes.string,
href: PropTypes.any,
legacyBehavior: PropTypes.bool,
linkAs: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
locale: PropTypes.string,
noLinkStyle: PropTypes.bool,
Expand Down

0 comments on commit c0a420c

Please sign in to comment.