From 704bc0c28fe1cf05ef805bd213a919751368b781 Mon Sep 17 00:00:00 2001 From: rakannimer Date: Mon, 30 Sep 2019 16:05:59 -0400 Subject: [PATCH] fix(gatsby-theme-docz): check for window before reading location --- core/gatsby-theme-docz/src/components/NavLink/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/gatsby-theme-docz/src/components/NavLink/index.js b/core/gatsby-theme-docz/src/components/NavLink/index.js index 0ea9dbde2..bcad5400b 100644 --- a/core/gatsby-theme-docz/src/components/NavLink/index.js +++ b/core/gatsby-theme-docz/src/components/NavLink/index.js @@ -13,6 +13,13 @@ 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 @@ -20,7 +27,7 @@ export const NavLink = ({ item, ...props }) => { 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 (