Skip to content

Commit

Permalink
fix: path current slug to DocsNav due to usePathname not working with…
Browse files Browse the repository at this point in the history
… SSG'ed page
  • Loading branch information
kevinwolfcr committed Sep 6, 2023
1 parent 2f7456f commit 5532ed3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import type { getDocsConfig } from "@/data/docs"

import { IconBrandGithub } from "@tabler/icons-react"
import Link from "next/link"
import { usePathname } from "next/navigation"

import { Nav } from "@/components/nav"
import { Tooltip } from "@/components/tooltip"

export type DocsNavProps = {
title: string
repo: string
slug: string
menus: NonNullable<Awaited<ReturnType<typeof getDocsConfig>>>["menus"]
}

export function DocsNav({ title, repo, menus }: DocsNavProps) {
const pathname = usePathname()

export function DocsNav({ title, repo, slug, menus }: DocsNavProps) {
return (
<Nav
className="sm:w-[280px] sm:flex-shrink-0 sm:justify-start sm:items-start p-0 gap-0"
Expand Down Expand Up @@ -51,7 +49,7 @@ export function DocsNav({ title, repo, menus }: DocsNavProps) {
<Link
key={item.href}
href={href}
aria-current={href === pathname ? "page" : undefined}
aria-current={href === slug ? "page" : undefined}
aria-label={item.label}
className="border-l border-base-6 aria-[current=page]:border-accent-8 typography-2 text-dimmed hover:text-base aria-[current=page]:text-base aria-[current=page]:font-medium py-1 pl-3 transition-colors"
onClick={() => setIsExpanded(false)}
Expand Down
2 changes: 1 addition & 1 deletion src/app/docs/[project]/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default async function DocsPage({ params: { project, slug = [] } }: DocsP

return (
<Fragment>
<DocsNav title={config.title} repo={config.repo} menus={config.menus} />
<DocsNav title={config.title} repo={config.repo} slug={`/${slug.join("/")}`} menus={config.menus} />
<Main className="relative z-20">
<Hero
title={page.meta.title || config.title}
Expand Down

1 comment on commit 5532ed3

@vercel
Copy link

@vercel vercel bot commented on 5532ed3 Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.