Skip to content

Commit a3642b0

Browse files
authored
fix: add external link logic for navigation links (#2249)
1 parent 22d28be commit a3642b0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/components/Nav/Desktop.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,14 @@ const LinkToPage = React.memo(function LinkToPage({
210210
asPath: string
211211
}) {
212212
const isActive = route === asPath.split('/?')[0].split('?')[0]
213+
const isExternal = route.startsWith('http')
213214

214215
return (
215216
<BasicLink
216217
href={route}
217218
data-linkactive={isActive}
219+
target={isExternal ? '_blank' : undefined}
220+
rel={isExternal ? 'noopener noreferrer' : undefined}
218221
className="group/link -ml-1.5 flex flex-1 items-center gap-3 rounded-md p-1.5 hover:bg-black/5 focus-visible:bg-black/5 data-[linkactive=true]:bg-(--link-active-bg) data-[linkactive=true]:text-white dark:hover:bg-white/10 dark:focus-visible:bg-white/10"
219222
>
220223
{icon ? (

src/components/Nav/Mobile/Menu.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,13 @@ const LinkToPage = React.memo(function LinkToPage({
168168
setShow: (show: boolean) => void
169169
}) {
170170
const isActive = route === asPath.split('/?')[0].split('?')[0]
171+
const isExternal = route.startsWith('http')
172+
171173
return (
172174
<BasicLink
173175
href={route}
176+
target={isExternal ? '_blank' : undefined}
177+
rel={isExternal ? 'noopener noreferrer' : undefined}
174178
data-linkactive={isActive}
175179
className="-ml-1.5 flex items-center gap-3 rounded-md p-1.5 hover:bg-black/5 focus-visible:bg-black/5 data-[linkactive=true]:bg-(--link-active-bg) data-[linkactive=true]:text-white dark:hover:bg-white/10 dark:focus-visible:bg-white/10"
176180
onClick={() => setShow(false)}

0 commit comments

Comments
 (0)