Skip to content

Commit

Permalink
Make redirects in the Link component only for links in the current do…
Browse files Browse the repository at this point in the history
…main (#1151)

Co-authored-by: Pavel Grinchenko <[email protected]>
  • Loading branch information
pavelgrinchenko and psdcoder authored Apr 15, 2020
1 parent dfb2140 commit c29a07c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/components/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ const Link: React.FC<ILinkProps> = ({ href, ...restProps }) => {
href = currentLocation.pathname + href
}

// Replace link href with redirect if it exists
const [, redirectUrl] = getRedirect(location.host, location.pathname)
if (redirectUrl) {
href = isRelative(redirectUrl)
? redirectUrl + currentLocation.search
: redirectUrl
if (location.host === currentLocation.host) {
// Replace link href with redirect if it exists
const [, redirectUrl] = getRedirect(location.host, location.pathname)

if (redirectUrl) {
href = isRelative(redirectUrl)
? redirectUrl + currentLocation.search
: redirectUrl
}
}

return <ResultLinkComponent href={href} {...restProps} onClick={onClick} />
Expand Down

0 comments on commit c29a07c

Please sign in to comment.