File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -3,17 +3,37 @@ import { usePageContext } from "./usePageContext";
33
44export { Link } ;
55
6- function Link ( props : {
6+ function Link ( {
7+ href,
8+ className,
9+ children,
10+ } : {
711 href ?: string ;
812 className ?: string ;
913 children : React . ReactNode ;
1014} ) {
15+ let base = import . meta. env . BASE_URL ;
16+ let processedHref = href ;
17+ if ( base ) {
18+ if ( ! href ?. startsWith ( "/" ) ) {
19+ throw new Error ( "Link href should start with /" ) ;
20+ }
21+ if ( base . endsWith ( "/" ) ) {
22+ base = base . slice ( 0 , - 1 ) ;
23+ }
24+ processedHref = `${ base } ${ href } ` ;
25+ }
26+
1127 const pageContext = usePageContext ( ) ;
12- const className = [
13- props . className ,
14- pageContext . urlPathname === props . href && "is-active" ,
28+ const completeClassName = [
29+ className ,
30+ pageContext . urlPathname === href && "is-active" ,
1531 ]
1632 . filter ( Boolean )
1733 . join ( " " ) ;
18- return < a { ...props } className = { className } /> ;
34+ return (
35+ < a href = { processedHref } className = { completeClassName } >
36+ { children }
37+ </ a >
38+ ) ;
1939}
You can’t perform that action at this time.
0 commit comments