diff --git a/components/share.js b/components/share.js index ab32a431..42575e58 100644 --- a/components/share.js +++ b/components/share.js @@ -3,13 +3,22 @@ import ShareIcon from '../svgs/share-fill.svg' import copy from 'clipboard-copy' import { useMe } from './me' import { useToast } from './toast' +import { SSR } from '../lib/constants' + +const getShareUrl = (item, me) => { + const path = `/items/${item?.id}${me ? `/r/${me.name}` : ''}` + if (!SSR) { + return `${window.location.protocol}//${window.location.host}${path}` + } + return `https://stacker.news${path}` +} export default function Share ({ item }) { const me = useMe() const toaster = useToast() - const url = `https://stacker.news/items/${item.id}${me ? `/r/${me.name}` : ''}` + const url = getShareUrl(item, me) - return typeof window !== 'undefined' && navigator?.share + return !SSR && navigator?.share ? (