Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e2b8ab

Browse files
mueschapieh
authored andcommitted
fix(compontent): fix links with undefined in docs-table-of-con… (gatsbyjs#19851)
1 parent 03d2de1 commit 4e2b8ab

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

www/src/components/docs-table-of-contents.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @jsx jsx */
22
import { jsx } from "theme-ui"
33
import { Link } from "gatsby"
4-
import { mediaQueries, colors } from "../gatsby-plugin-theme-ui"
4+
import { colors, mediaQueries } from "../gatsby-plugin-theme-ui"
55

66
function isUnderDepthLimit(depth, maxDepth) {
77
if (maxDepth === null) {
@@ -17,38 +17,40 @@ function isUnderDepthLimit(depth, maxDepth) {
1717
function createItems(items, location, depth, maxDepth) {
1818
return (
1919
items &&
20-
items.map(item => (
20+
items.map((item, index) => (
2121
<li
2222
sx={{ [mediaQueries.xl]: { fontSize: 1 } }}
23-
key={location.pathname + item.url}
23+
key={location.pathname + (item.url || depth + `-` + index)}
2424
>
25-
<Link
26-
sx={{
27-
"&&": {
28-
color: `textMuted`,
29-
border: 0,
30-
transition: t =>
31-
`all ${t.transition.speed.fast} ${t.transition.curve.default}`,
32-
":hover": {
33-
color: `link.color`,
34-
borderBottom: t => `1px solid ${t.colors.link.hoverBorder}`,
25+
{item.url && (
26+
<Link
27+
sx={{
28+
"&&": {
29+
color: `textMuted`,
30+
border: 0,
31+
transition: t =>
32+
`all ${t.transition.speed.fast} ${t.transition.curve.default}`,
33+
":hover": {
34+
color: `link.color`,
35+
borderBottom: t => `1px solid ${t.colors.link.hoverBorder}`,
36+
},
3537
},
36-
},
37-
}}
38-
getProps={({ href, location }) =>
39-
location && location.href && location.href.includes(href)
40-
? {
41-
style: {
42-
color: colors.link.color,
43-
borderBottom: `1px solid ${colors.link.hoverBorder}`,
44-
},
45-
}
46-
: null
47-
}
48-
to={location.pathname + item.url}
49-
>
50-
{item.title}
51-
</Link>
38+
}}
39+
getProps={({ href, location }) =>
40+
location && location.href && location.href.includes(href)
41+
? {
42+
style: {
43+
color: colors.link.color,
44+
borderBottom: `1px solid ${colors.link.hoverBorder}`,
45+
},
46+
}
47+
: null
48+
}
49+
to={location.pathname + item.url}
50+
>
51+
{item.title}
52+
</Link>
53+
)}
5254
{item.items && isUnderDepthLimit(depth, maxDepth) && (
5355
<ul sx={{ color: `textMuted`, listStyle: `none`, ml: 5 }}>
5456
{createItems(item.items, location, depth + 1, maxDepth)}

0 commit comments

Comments
 (0)