File tree Expand file tree Collapse file tree 2 files changed +35
-6
lines changed
src/components/Navigation Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 1616
1717import React , { type ReactNode } from 'react' ;
1818import Link from '@docusaurus/Link' ;
19+ import { useLocation } from '@docusaurus/router' ;
20+ import useBaseUrl from '@docusaurus/useBaseUrl' ;
1921import styles from './styles.module.css' ;
2022
21- function Navigation ( { links } ) {
23+ interface NavLink {
24+ label : string ;
25+ href : string ;
26+ }
27+
28+ interface NavigationProps {
29+ links : NavLink [ ] ;
30+ }
31+
32+ function Navigation ( { links } : NavigationProps ) {
33+ const location = useLocation ( ) ;
34+
2235 return (
2336 < nav className = "container" >
2437 < ul className = { styles . nav } >
25- { links . map ( ( link , i ) => (
26- < li key = { i } className = { styles . links } >
27- < Link href = { link . href } > { link . label } </ Link >
28- </ li >
29- ) ) }
38+ { links . map ( ( link , i ) => {
39+ const baseHref = useBaseUrl ( link . href ) ;
40+ const isActive = location . pathname === baseHref ||
41+ location . pathname . startsWith ( baseHref + '/' ) ;
42+
43+ return (
44+ < li key = { i } className = { `${ styles . links } ${ isActive ? styles . active : '' } ` } >
45+ < Link
46+ href = { link . href }
47+ aria-current = { isActive ? 'page' : undefined }
48+ >
49+ { link . label }
50+ </ Link >
51+ </ li >
52+ ) ;
53+ } ) }
3054 </ ul >
3155 </ nav >
3256 ) ;
Original file line number Diff line number Diff line change 44 gap : 2rem ;
55 justify-content : center;
66}
7+
8+ .active a {
9+ font-weight : 700 ;
10+ text-decoration : underline;
11+ }
You can’t perform that action at this time.
0 commit comments