Skip to content

Commit 42f425a

Browse files
[docs] Fix broken Next and Previous links (#29711)
Co-authored-by: Olivier Tassinari <[email protected]>
1 parent 096a9e7 commit 42f425a

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

docs/src/modules/components/AppNavDrawerItem.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@ const iconsMap = {
3131
ReaderIcon: ChromeReaderModeOutlined,
3232
};
3333

34-
const Item = styled(
35-
function Item({ component: Component = 'div', ...props }) {
36-
return <Component {...props} />;
37-
},
38-
{
39-
// disable `as` prop
40-
shouldForwardProp: () => true,
41-
},
42-
)(({ theme }) => ({
34+
const Item = styled(function Item({ component: Component = 'div', ...props }) {
35+
return <Component {...props} />;
36+
})(({ theme }) => ({
4337
...theme.typography.body2,
4438
display: 'flex',
4539
borderRadius: 5,

docs/src/modules/components/AppTableOfContents.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export default function AppTableOfContents(props) {
196196
const itemLink = (item, secondary) => (
197197
<NavItem
198198
display="block"
199-
href={`${activePage.linkProps?.as ?? activePage.pathname}#${item.hash}`}
199+
href={`${activePage.linkProps?.linkAs ?? activePage.pathname}#${item.hash}`}
200200
underline="none"
201201
onClick={handleClick(item.hash)}
202202
active={activeState === item.hash}

docs/src/modules/components/Link.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type LinkProps = {
5151
activeClassName?: string;
5252
as?: NextLinkProps['as'];
5353
href: NextLinkProps['href'];
54+
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
5455
noLinkStyle?: boolean;
5556
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
5657
Omit<MuiLinkProps, 'href'>;
@@ -60,9 +61,10 @@ export type LinkProps = {
6061
const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props, ref) {
6162
const {
6263
activeClassName = 'active',
63-
as: linkAsProp,
64+
as: asProp,
6465
className: classNameProps,
6566
href,
67+
linkAs: linkAsProp,
6668
noLinkStyle,
6769
role, // Link don't have roles.
6870
...other
@@ -86,12 +88,12 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
8688
return <MuiLink className={className} href={href} ref={ref} {...other} />;
8789
}
8890

89-
let linkAs = linkAsProp || (href as string);
91+
let linkAs = linkAsProp || asProp || (href as string);
9092
if (
9193
userLanguage !== 'en' &&
92-
typeof href === 'string' &&
93-
href.indexOf('/') === 0 &&
94-
href.indexOf('/blog') !== 0
94+
pathname &&
95+
pathname.indexOf('/') === 0 &&
96+
pathname.indexOf('/blog') !== 0
9597
) {
9698
linkAs = `/${userLanguage}${linkAs}`;
9799
}

docs/src/pages.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,21 @@ const pages: readonly MuiPage[] = [
226226
title: 'GridPrintExportOptions',
227227
},
228228
].map((page) => {
229-
return { ...page, linkProps: { as: `${page.pathname.replace(/^\/api-docs/, '/api')}/` } };
229+
return {
230+
...page,
231+
linkProps: { linkAs: `${page.pathname.replace(/^\/api-docs/, '/api')}/` },
232+
};
230233
}),
231234
},
232235
]
233236
.sort((a, b) =>
234237
a.pathname.replace('/api-docs/', '').localeCompare(b.pathname.replace('/api-docs/', '')),
235238
)
236239
.map((page) => {
237-
return { ...page, linkProps: { as: `${page.pathname.replace(/^\/api-docs/, '/api')}/` } };
240+
return {
241+
...page,
242+
linkProps: { linkAs: `${page.pathname.replace(/^\/api-docs/, '/api')}/` },
243+
};
238244
}),
239245
},
240246
{

examples/nextjs-with-styled-components-typescript/src/Link.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type LinkProps = {
4141
activeClassName?: string;
4242
as?: NextLinkProps['as'];
4343
href: NextLinkProps['href'];
44+
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
4445
noLinkStyle?: boolean;
4546
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
4647
Omit<MuiLinkProps, 'href'>;

examples/nextjs-with-typescript/src/Link.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type LinkProps = {
4141
activeClassName?: string;
4242
as?: NextLinkProps['as'];
4343
href: NextLinkProps['href'];
44+
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
4445
noLinkStyle?: boolean;
4546
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
4647
Omit<MuiLinkProps, 'href'>;

examples/nextjs/src/Link.js

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Link.propTypes = {
9191
as: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
9292
className: PropTypes.string,
9393
href: PropTypes.any,
94+
linkAs: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
9495
noLinkStyle: PropTypes.bool,
9596
role: PropTypes.string,
9697
};

0 commit comments

Comments
 (0)