initial commit
This commit is contained in:
22
components/ui/Link.tsx
Normal file
22
components/ui/Link.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import Link from 'next/link'
|
||||
import type { LinkProps } from 'next/link'
|
||||
import { AnchorHTMLAttributes } from 'react'
|
||||
|
||||
const CustomLink = ({ href, ...rest }: LinkProps & AnchorHTMLAttributes<HTMLAnchorElement>) => {
|
||||
const isInternalLink = href && href.startsWith('/')
|
||||
const isAnchorLink = href && href.startsWith('#')
|
||||
|
||||
if (isInternalLink) {
|
||||
return <Link className="break-words" href={href} {...rest} />
|
||||
}
|
||||
|
||||
if (isAnchorLink) {
|
||||
return <a className="break-words" href={href} {...rest} />
|
||||
}
|
||||
|
||||
return (
|
||||
<a className="break-words" target="_blank" rel="noopener noreferrer" href={href} {...rest} />
|
||||
)
|
||||
}
|
||||
|
||||
export default CustomLink
|
||||
Reference in New Issue
Block a user