diff --git a/newamericadotorg/assets/react/report/components/FeaturedSections.js b/newamericadotorg/assets/react/report/components/FeaturedSections.js index 4695c3668..326ed8d1c 100644 --- a/newamericadotorg/assets/react/report/components/FeaturedSections.js +++ b/newamericadotorg/assets/react/report/components/FeaturedSections.js @@ -4,6 +4,19 @@ import React, { Component } from 'react'; import { Highlight, DataViz, Resource } from '../../components/Icons'; import { Link } from 'react-router-dom'; +function PossiblyExternalLink({children, ...props}) { + // If the given link url is relative to the site domain, return a + // `Link` component to tie into react-router. If it's an external + // link, return an plain old `a` tag. + let relativizedTarget = props.to.replace(location.origin, ''); + + if (relativizedTarget.startsWith('/') || !relativizedTarget) { + return ({children}); + } else { + return ({children}); + } +} + const iconsMap = { 'Highlight': Highlight, 'Data Visualization': DataViz, @@ -19,7 +32,7 @@ const FeaturedIcon = ({ featuredType, Icon }) => ( const Featured = ({ section }) => (