You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
830 B
42 lines
830 B
2 years ago
|
import Link from "next/link"
|
||
|
import PropTypes from "prop-types"
|
||
|
import { linkPropTypes } from "utils/types"
|
||
|
|
||
|
const CustomLink = ({ link, children }) => {
|
||
|
const isInternalLink = link.url.startsWith("/")
|
||
|
|
||
|
// For internal links, use the Next.js Link component
|
||
|
if (isInternalLink) {
|
||
|
return (
|
||
|
<Link href={link.url}>
|
||
|
<a>{children}</a>
|
||
|
</Link>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
// Plain <a> tags for external links
|
||
|
if (link.newTab) {
|
||
|
return (
|
||
|
<a href={link.url} target="_blank" rel="noopener noreferrer">
|
||
|
{children}
|
||
|
</a>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<a href={link.url} target="_self">
|
||
|
{children}
|
||
|
</a>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
CustomLink.propTypes = {
|
||
|
link: linkPropTypes,
|
||
|
children: PropTypes.oneOfType([
|
||
|
PropTypes.arrayOf(PropTypes.node),
|
||
|
PropTypes.node,
|
||
|
]).isRequired,
|
||
|
}
|
||
|
|
||
|
export default CustomLink
|