Skip to content

Commit

Permalink
fix(gatsby-theme-docz): check for window before reading location
Browse files Browse the repository at this point in the history
  • Loading branch information
rakannimer committed Sep 30, 2019
1 parent 51949cd commit 704bc0c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/gatsby-theme-docz/src/components/NavLink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ const getHeadings = (route, docs) => {
return headings ? headings.filter(heading => heading.depth === 2) : []
}

const getCurrentHash = () => {
if (typeof window === 'undefined') {
return ''
}
return window.location ? window.location.hash : ''
}

export const NavLink = ({ item, ...props }) => {
const docs = useDocs()
const to = item.route
const headings = docs && getHeadings(to, docs)
const current = useCurrentDoc()
const isCurrent = item.route === current.route
const showHeadings = isCurrent && headings && headings.length > 0
const currentHash = location ? location.hash : ''
const currentHash = getCurrentHash()
return (
<React.Fragment>
<Link {...props} to={to} sx={styles.link} activeClassName="active" />
Expand Down

0 comments on commit 704bc0c

Please sign in to comment.