File tree Expand file tree Collapse file tree 5 files changed +35
-11
lines changed Expand file tree Collapse file tree 5 files changed +35
-11
lines changed Original file line number Diff line number Diff line change 1
1
'use client' ;
2
2
3
- import Link from 'next/link' ;
4
3
import Image from 'next/image' ;
5
4
6
5
import { GitHubBrandIcon } from '@/components/icons/platform/GitHubBrandIcon' ;
7
6
import { cn } from '@/lib/helper' ;
8
7
import { ProjectModel , projectList } from '~/index' ;
8
+ import { PrefetchLink } from '@/components/modules/shared/PrefetchLink' ;
9
9
10
10
export default function Projects ( ) {
11
11
return (
@@ -41,7 +41,7 @@ const ProjectCardList = ({ data }: { data: ProjectModel[] }) => (
41
41
) ;
42
42
const ProjectCard = ( { project } : { project : ProjectModel } ) => {
43
43
return (
44
- < Link
44
+ < PrefetchLink
45
45
href = { project . url }
46
46
key = { project . id }
47
47
className = "group flex shrink-0 grid-cols-[60px_2fr] flex-col items-center gap-4 md:grid"
@@ -59,7 +59,7 @@ const ProjectCard = ({ project }: { project: ProjectModel }) => {
59
59
{ project . desc }
60
60
</ span >
61
61
</ span >
62
- </ Link >
62
+ </ PrefetchLink >
63
63
) ;
64
64
} ;
65
65
Original file line number Diff line number Diff line change 1
1
import Link from 'next/link' ;
2
2
3
+ import { PrefetchLink } from '@/components/modules/shared/PrefetchLink' ;
3
4
import ThemeSwitcher from '@/components/ui/ThemeSwitcher' ;
4
5
5
6
const Footer = ( ) => {
@@ -12,11 +13,11 @@ const Footer = () => {
12
13
< div className = "relative mx-auto max-w-7xl lg:px-8 h-full flex flex-row items-center justify-around" >
13
14
< div className = " flex items-center gap-x-4 font-mono" >
14
15
< span className = "" >
15
- < Link href = { '/' } >
16
+ < PrefetchLink href = { '/' } >
16
17
< span className = " relative before:content-[''] before:absolute before:bottom-[-2px] before:w-[0px] hover:before:w-[100%] before:h-[1px] before:bg-[var(--accent-color)] before:transition-all before:duration-300" >
17
18
关于我
18
19
</ span >
19
- </ Link >
20
+ </ PrefetchLink >
20
21
</ span >
21
22
< span className = "" >
22
23
< Link href = { '/' } >
Original file line number Diff line number Diff line change 3
3
import { LayoutGroup , m , useMotionTemplate , useMotionValue } from 'framer-motion' ;
4
4
import React , { memo } from 'react' ;
5
5
import { usePathname , useParams } from 'next/navigation' ;
6
- import Link from 'next/link' ;
7
6
8
7
import { MenuPopover } from './MenuPopover' ;
9
8
10
9
import { cn } from '@/lib/helper' ;
11
10
import { IHeaderMenu , headerMenuConfig } from '~/router' ;
11
+ import { PrefetchLink } from '@/components/modules/shared/PrefetchLink' ;
12
12
13
13
export const HeaderCenterContent = ( ) => {
14
14
const params = useParams ( ) ;
@@ -137,7 +137,7 @@ function AnimatedItem({
137
137
} ) {
138
138
return (
139
139
< div >
140
- < Link
140
+ < PrefetchLink
141
141
href = { href }
142
142
className = { cn (
143
143
'relative block whitespace-nowrap px-4 py-2 transition' ,
@@ -156,7 +156,7 @@ function AnimatedItem({
156
156
layoutId = "active-nav-item"
157
157
/>
158
158
) }
159
- </ Link >
159
+ </ PrefetchLink >
160
160
</ div >
161
161
) ;
162
162
}
Original file line number Diff line number Diff line change 1
- import Link from 'next/link' ;
2
1
import { memo } from 'react' ;
3
2
4
3
import { PostItemHoverOverlay } from './PostItemHoverOverlay' ;
4
+ import { PrefetchLink } from '../shared/PrefetchLink' ;
5
5
6
6
import dayjs from '@/lib/dayjs' ;
7
7
import { MdiClockOutline } from '@/components/icons/clock' ;
@@ -12,7 +12,10 @@ export const PostItem = memo<{ data: PostItemType }>(function PostItem({ data })
12
12
const postLink = `/notes/${ data . path } ` ;
13
13
14
14
return (
15
- < Link href = { postLink } className = "relative flex flex-col py-8 focus-visible:!shadow-none gap-2" >
15
+ < PrefetchLink
16
+ href = { postLink }
17
+ className = "relative flex flex-col py-8 focus-visible:!shadow-none gap-2"
18
+ >
16
19
< PostItemHoverOverlay />
17
20
< h2 className = "relative text-balance break-words text-2xl font-medium" > { data . title } </ h2 >
18
21
@@ -27,6 +30,6 @@ export const PostItem = memo<{ data: PostItemType }>(function PostItem({ data })
27
30
< p > { data . tag } </ p >
28
31
</ span >
29
32
</ div >
30
- </ Link >
33
+ </ PrefetchLink >
31
34
) ;
32
35
} ) ;
Original file line number Diff line number Diff line change
1
+ import Link from 'next/link' ;
2
+ import { useState , useCallback } from 'react' ;
3
+
4
+ interface PrefetchLinkProps extends React . ComponentProps < typeof Link > {
5
+ href : string ;
6
+ }
7
+
8
+ export const PrefetchLink : React . FC < PrefetchLinkProps > = ( { href, children, ...props } ) => {
9
+ const [ prefetch , setPrefetch ] = useState ( false ) ;
10
+
11
+ const handleMouseEnter = useCallback ( ( ) => {
12
+ setPrefetch ( true ) ;
13
+ } , [ ] ) ;
14
+
15
+ return (
16
+ < Link href = { href } prefetch = { prefetch } onMouseEnter = { handleMouseEnter } { ...props } >
17
+ { children }
18
+ </ Link >
19
+ ) ;
20
+ } ;
You can’t perform that action at this time.
0 commit comments