Skip to content

Commit 1fa30e6

Browse files
[docs-infra] Improve support for absolute locale URL
1 parent d4c5e8d commit 1fa30e6

File tree

7 files changed

+10
-42
lines changed

7 files changed

+10
-42
lines changed

docs/pages/blog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function PostPreview(props: BlogPost) {
8181
>
8282
<Link
8383
aria-describedby={`describe-${props.slug}`}
84-
href={`/blog/${props.slug}`}
84+
href={`/blog/${props.slug}/`}
8585
sx={{
8686
color: 'text.primary',
8787
'&:hover': {

docs/src/modules/components/AppNavDrawerItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export default function AppNavDrawerItem(props) {
273273
} = props;
274274
const [open, setOpen] = React.useState(initiallyExpanded);
275275
const handleClick = (event) => {
276-
// Ignore the action if opening the link in a new tab
276+
// Ignore click events meant for native link handling, e.g. open in new tab
277277
if (samePageLinkNavigation(event)) {
278278
return;
279279
}

docs/src/modules/components/AppTableOfContents.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default function AppTableOfContents(props) {
204204
useThrottledOnScroll(items.length > 0 ? findActiveIndex : null, 166);
205205

206206
const handleClick = (hash) => (event) => {
207-
// Ignore click for new tab/new window behavior
207+
// Ignore click events meant for native link handling, e.g. open in new tab
208208
if (samePageLinkNavigation(event)) {
209209
return;
210210
}

docs/src/modules/components/Link.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,8 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
9696
[activeClassName]: shouldBeActive && activeClassName,
9797
});
9898

99-
const isExternal =
100-
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0);
10199
const userLanguage = useUserLanguage();
102100

103-
if (isExternal) {
104-
if (noLinkStyle) {
105-
return <Anchor className={className} href={href} ref={ref} {...other} />;
106-
}
107-
108-
return <MuiLink className={className} href={href} ref={ref} {...other} />;
109-
}
110-
111101
let linkAs = linkAsProp || as || (href as string);
112102
if (
113103
userLanguage !== 'en' &&

docs/src/modules/components/MarkdownLinks.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ function isLink(event) {
2222
activeElement = activeElement.parentElement;
2323
}
2424

25-
// Ignore non internal link clicks
25+
// Ignore non internal link clicks.
26+
// Absolute URLs can be internal, we delegate this to Next.js's router
2627
if (
2728
activeElement === null ||
2829
activeElement.nodeName !== 'A' ||
2930
activeElement.getAttribute('target') === '_blank' ||
30-
activeElement.getAttribute('data-no-markdown-link') === 'true' ||
31-
activeElement.getAttribute('href').indexOf('/') !== 0
31+
activeElement.getAttribute('data-no-markdown-link') === 'true'
3232
) {
3333
return null;
3434
}
@@ -40,13 +40,13 @@ function isLink(event) {
4040
* @param {MouseEvent} event
4141
*/
4242
function handleClick(event) {
43-
const activeElement = isLink(event);
44-
if (activeElement === null) {
43+
// Ignore click events meant for native link handling, e.g. open in new tab
44+
if (samePageLinkNavigation(event)) {
4545
return;
4646
}
4747

48-
// Ignore click meant for native link handling, e.g. open in new tab
49-
if (samePageLinkNavigation(event)) {
48+
const activeElement = isLink(event);
49+
if (activeElement === null) {
5050
return;
5151
}
5252

examples/material-ui-nextjs-pages-router-ts/src/Link.tsx

-11
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
8282
[activeClassName]: router.pathname === pathname && activeClassName,
8383
});
8484

85-
const isExternal =
86-
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0);
87-
88-
if (isExternal) {
89-
if (noLinkStyle) {
90-
return <Anchor className={className} href={href} ref={ref} {...other} />;
91-
}
92-
93-
return <MuiLink className={className} href={href} ref={ref} {...other} />;
94-
}
95-
9685
const linkAs = linkAsProp || as;
9786
const nextjsProps = {
9887
to: href,

examples/material-ui-nextjs-pages-router/src/Link.js

-11
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ const Link = React.forwardRef(function Link(props, ref) {
7878
[activeClassName]: router.pathname === pathname && activeClassName,
7979
});
8080

81-
const isExternal =
82-
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0);
83-
84-
if (isExternal) {
85-
if (noLinkStyle) {
86-
return <Anchor className={className} href={href} ref={ref} {...other} />;
87-
}
88-
89-
return <MuiLink className={className} href={href} ref={ref} {...other} />;
90-
}
91-
9281
const linkAs = linkAsProp || as;
9382
const nextjsProps = {
9483
to: href,

0 commit comments

Comments
 (0)