Skip to content

Commit

Permalink
use 'next/link' for sidenav links
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Lozano committed Dec 13, 2023
1 parent 2eb321a commit 4df2e6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/theme/components/layout/nav-drawer/NavDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import NextLink from 'next/link'
import {Box, IconButton, Link, ThemeProvider} from '@primer/react'
import {XIcon} from '@primer/octicons-react'

Expand Down Expand Up @@ -34,7 +35,7 @@ export function NavDrawer({isOpen, onDismiss, navItems}: NavDrawerProps) {
}}
>
<Box sx={{py: 20, pl: 4, pr: 3, alignItems: 'center', justifyContent: 'space-between', display: 'flex'}}>
<Link href="https://primer.style" sx={{fontWeight: 'bold', color: 'inherit'}}>
<Link as={NextLink} href="https://primer.style" sx={{fontWeight: 'bold', color: 'inherit'}}>
Explore
</Link>
<IconButton icon={XIcon} aria-label="Close" onClick={onDismiss} variant="invisible" />
Expand Down
19 changes: 16 additions & 3 deletions packages/theme/components/layout/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useMemo} from 'react'
import NextLink from 'next/link'
import {NavList} from '@primer/react'
import {Folder, MdxFile, PageMapItem} from 'nextra'
import {useRouter} from 'next/router'
Expand Down Expand Up @@ -94,7 +95,12 @@ export function Sidebar({pageMap}: SidebarProps) {

if (item.kind === 'MdxPage') {
return (
<NavList.Item key={item.name} href={`${basePath}${item.route}`} sx={{textTransform: 'capitalize'}}>
<NavList.Item
as={NextLink}
key={item.name}
href={`${basePath}${item.route}`}
sx={{textTransform: 'capitalize'}}
>
{item.frontMatter?.title ?? item.name}
</NavList.Item>
)
Expand All @@ -109,7 +115,7 @@ export function Sidebar({pageMap}: SidebarProps) {
const shouldShowTabs = indexPage.frontMatter?.['show-tabs'] ?? false
if (shouldShowTabs) {
return (
<NavList.Item key={indexPage.name} href={`${basePath}${indexPage.route}`}>
<NavList.Item as={NextLink} key={indexPage.name} href={`${basePath}${indexPage.route}`}>
{(indexPage as MdxFile).frontMatter?.title || item.name}
</NavList.Item>
)
Expand All @@ -129,6 +135,7 @@ export function Sidebar({pageMap}: SidebarProps) {
if (child.kind === 'MdxPage') {
return (
<NavList.Item
as={NextLink}
key={child.name}
href={`${basePath}${child.route}`}
aria-current={child.route === router.pathname ? 'page' : undefined}
Expand All @@ -144,6 +151,7 @@ export function Sidebar({pageMap}: SidebarProps) {
)
return (
<NavList.Item
as={NextLink}
key={`${(landingPageItem as MdxFile).route}`}
href={`${basePath}${(landingPageItem as MdxFile).route}`}
sx={{textTransform: 'capitalize'}}
Expand All @@ -170,7 +178,12 @@ export function Sidebar({pageMap}: SidebarProps) {
const LeadingIcon = getOcticonForType(leadingIcon)

return (
<NavList.Item key={link.title} href={link.href} target={isExternalUrl ? '_blank' : undefined}>
<NavList.Item
as={NextLink}
key={link.title}
href={link.href}
target={isExternalUrl ? '_blank' : undefined}
>
<NavList.LeadingVisual>{LeadingIcon && <LeadingIcon />}</NavList.LeadingVisual>
{link.title}
{isExternalUrl && (
Expand Down

0 comments on commit 4df2e6a

Please sign in to comment.