Skip to content

Commit

Permalink
fix(docz-theme-default): allow use of link component in ssr (#854)
Browse files Browse the repository at this point in the history
check environment before using global `location` variable in link component

fixes #832
  • Loading branch information
AryanJ-NYC authored and pedronauck committed May 8, 2019
1 parent 0fb41c8 commit 90c27e0
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions core/docz-theme-default/src/components/ui/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ type LinkProps = React.AnchorHTMLAttributes<any>
export const Link: SFC<LinkProps> = ({ href, ...props }) => {
const { separator, linkComponent: Link } = useConfig()
const docs = useDocs()
const toCheck = useMemo(
() =>
[
location.pathname
.split(separator)
.slice(0, -1)
.join(separator)
.slice(1),
(href || '').replace(/^(?:\.\/)+/gi, ''),
].join('/'),
[separator]
)
const toCheck =
typeof window === 'undefined'
? null
: useMemo(
() =>
[
location.pathname
.split(separator)
.slice(0, -1)
.join(separator)
.slice(1),
(href || '').replace(/^(?:\.\/)+/gi, ''),
].join('/'),
[separator]
)

const matched = docs && docs.find(doc => doc.filepath === toCheck)
const nHref = matched ? matched.route : href
Expand Down

0 comments on commit 90c27e0

Please sign in to comment.