Skip to content

Commit 42c7512

Browse files
committed
fix: update Link
1 parent e3139ae commit 42c7512

File tree

27 files changed

+115
-92
lines changed

27 files changed

+115
-92
lines changed

src/components/dropdown/AvatarWithDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useLoginContext } from '@/hooks/useLoginContext';
44

55
import LanguageSwitcher from '@/components/buttons/LanguageSwitcher';
66
import ThemeSwitcher from '@/components/buttons/ThemeSwitcher';
7-
import CustomLink from '@/components/links/CustomLink';
7+
import { CustomLink } from '@/components/links/CustomLink';
88

99
import { DEFAULT_AVATAR } from '@/utils/constants';
1010

src/components/home/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Link from 'next/link';
22
import { AiFillFire, AiOutlineEye } from 'react-icons/ai';
33
import { GoStar, GoVerified } from 'react-icons/go';
44

5-
import CustomLink from '@/components/links/CustomLink';
5+
import { CustomLink } from '@/components/links/CustomLink';
66

77
import { fromNow } from '@/utils/day';
88
import { numFormat } from '@/utils/util';

src/components/layout/ErrorPage.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Link from 'next/link';
21
import { IoIosArrowForward } from 'react-icons/io';
32

43
import LanguageSwitcher from '@/components/buttons/LanguageSwitcher';
54
import ThemeSwitcher from '@/components/buttons/ThemeSwitcher';
5+
import { NoPrefetchLink } from '@/components/links/CustomLink';
66

77
type Props = {
88
httpCode: number;
@@ -24,7 +24,7 @@ const ErrorPage = ({ t, httpCode }: Props) => {
2424
width={500}
2525
/>
2626
</div>
27-
<Link href='/'>
27+
<NoPrefetchLink href='/'>
2828
<a>
2929
<div className='group relative inline-flex cursor-pointer items-center overflow-hidden rounded border border-current px-7 py-2 text-blue-600 focus:outline-none focus:ring active:text-blue-500 dark:text-gray-500 dark:active:text-gray-500'>
3030
<span className='absolute right-0 translate-x-full transition-transform group-hover:-translate-x-4'>
@@ -36,27 +36,27 @@ const ErrorPage = ({ t, httpCode }: Props) => {
3636
</span>
3737
</div>
3838
</a>
39-
</Link>
39+
</NoPrefetchLink>
4040
<div className='mt-4 block text-xs text-gray-400'>
41-
<Link href='mailto:[email protected]'>
41+
<NoPrefetchLink href='mailto:[email protected]'>
4242
<a
4343
target='_blank'
4444
className='cursor-pointer hover:underline'
4545
rel='noreferrer'
4646
>
4747
<span>{t('footer.feedback')}</span>
4848
</a>
49-
</Link>
49+
</NoPrefetchLink>
5050
<span className='px-1'>·</span>
51-
<Link href='https://github.com/HelloGitHub-Team/geese'>
51+
<NoPrefetchLink href='https://github.com/HelloGitHub-Team/geese'>
5252
<a
5353
target='_blank'
5454
className='cursor-pointer hover:underline'
5555
rel='noreferrer'
5656
>
5757
<span>{t('footer.source')}</span>
5858
</a>
59-
</Link>
59+
</NoPrefetchLink>
6060

6161
<p className='mt-2'>
6262
<span className='cursor-default'>

src/components/layout/Footer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AiFillWechat, AiFillWeiboCircle } from 'react-icons/ai';
22
import { IoLogoRss } from 'react-icons/io';
33

44
import { FeedbackModal } from '@/components/dialog/Feedback';
5-
import CustomLink from '@/components/links/CustomLink';
5+
import { CustomLink } from '@/components/links/CustomLink';
66

77
import FooterLink from './FooterLink';
88

@@ -30,7 +30,11 @@ const Footer = ({ t }: SideProps) => {
3030
</div>
3131

3232
<p className='mt-2'>
33-
<FooterLink href='/help/ats'>{t('footer.agreement')}</FooterLink>
33+
<CustomLink className='inline' href='/help/ats'>
34+
<span className='cursor-pointer hover:text-blue-500'>
35+
{t('footer.agreement')}
36+
</span>
37+
</CustomLink>
3438
<span className='px-1 lg:px-1.5'>·</span>
3539
<FooterLink href='https://github.com/HelloGitHub-Team/geese'>
3640
{t('footer.source')}

src/components/links/CustomLink.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Props = {
99
onClick?: any;
1010
} & React.ComponentPropsWithoutRef<'div'>;
1111

12-
const CustomLink = ({ href, className, children, onClick }: Props) => {
12+
export const CustomLink = ({ href, className, children, onClick }: Props) => {
1313
const [isMobile, setIsMobile] = useState<boolean>(false);
1414
useEffect(() => {
1515
if (
@@ -35,4 +35,10 @@ const CustomLink = ({ href, className, children, onClick }: Props) => {
3535
);
3636
};
3737

38-
export default CustomLink;
38+
export const NoPrefetchLink = ({ href, children }: Props) => {
39+
return (
40+
<Link prefetch={false} href={href}>
41+
{children}
42+
</Link>
43+
);
44+
};

src/components/links/TagItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Link from 'next/link';
1+
import { NoPrefetchLink } from '@/components/links/CustomLink';
22

33
interface Props {
44
name: string;
@@ -7,11 +7,11 @@ interface Props {
77

88
const TagItem = ({ name, tid }: Props) => {
99
return (
10-
<Link href={`/?sort_by=hot&tid=${tid}`}>
10+
<NoPrefetchLink href={`/?sort_by=hot&tid=${tid}`}>
1111
<a className='inline-flex h-8 items-center justify-center rounded-lg pl-3 pr-3 text-sm font-bold text-blue-400 hover:bg-blue-400 hover:text-white'>
1212
{name}
1313
</a>
14-
</Link>
14+
</NoPrefetchLink>
1515
);
1616
};
1717

src/components/links/TagLink.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Link from 'next/link';
1+
import { NoPrefetchLink } from '@/components/links/CustomLink';
22

33
import { TagType } from '@/types/tag';
44

@@ -15,7 +15,9 @@ export default function TagLink(props: Props) {
1515
{props.items.map((item: TagType) => {
1616
return (
1717
<li className='shrink-0 grow-0 basis-auto' key={item.tid}>
18-
<Link href={`/?sort_by=${props.sort_by}&tid=${item.tid}`}>
18+
<NoPrefetchLink
19+
href={`/?sort_by=${props.sort_by}&tid=${item.tid}`}
20+
>
1921
{props.tid == item.tid ? (
2022
<a className='mt-1 mr-1 inline-flex h-6 items-center justify-center rounded-xl bg-gray-100 px-0 pl-2 pr-2 text-blue-500 dark:bg-gray-700 dark:focus:bg-gray-700'>
2123
{item.name}
@@ -25,7 +27,7 @@ export default function TagLink(props: Props) {
2527
{item.name}
2628
</a>
2729
)}
28-
</Link>
30+
</NoPrefetchLink>
2931
</li>
3032
);
3133
})}

src/components/navbar/ArticleBar.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import classNames from 'classnames';
2-
import Link from 'next/link';
32
import { useRouter } from 'next/router';
43
import { AiOutlineArrowLeft } from 'react-icons/ai';
54

5+
import { NoPrefetchLink } from '@/components/links/CustomLink';
6+
67
type Props = {
78
t: (key: string) => string;
89
};
@@ -41,12 +42,12 @@ const ArticleNavbar = ({ t }: Props) => {
4142
{t('nav.title')}
4243
</div>
4344
<div className='flex justify-end text-sm text-gray-500 dark:text-gray-400'>
44-
<Link href='/article?sort_by=last'>
45+
<NoPrefetchLink href='/article?sort_by=last'>
4546
<a className={linkClassName('last')}>{t('nav.last')}</a>
46-
</Link>
47-
<Link href='/article?sort_by=hot'>
47+
</NoPrefetchLink>
48+
<NoPrefetchLink href='/article?sort_by=hot'>
4849
<a className={linkClassName('hot')}>{t('nav.hot')}</a>
49-
</Link>
50+
</NoPrefetchLink>
5051
</div>
5152
</div>
5253
</div>

src/components/navbar/IndexBar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import classNames from 'classnames';
22
import { NextPage } from 'next';
3-
import Link from 'next/link';
43

54
import useTagHandling from '@/hooks/useTagHandling';
65

76
import { RepoModal } from '@/components/dialog/RepoModal';
7+
import { NoPrefetchLink } from '@/components/links/CustomLink';
88
import TagLink from '@/components/links/TagLink';
99

1010
type Props = {
@@ -31,12 +31,12 @@ const IndexBar: NextPage<Props> = ({ t, i18n_lang, tid, sort_by }) => {
3131
return (
3232
<div className='relative my-2 overflow-hidden bg-white dark:bg-gray-800 md:rounded-lg'>
3333
<div className='flex h-12 shrink grow items-center justify-start space-x-1 py-2 px-4 md:space-x-2'>
34-
<Link href={featuredURL}>
34+
<NoPrefetchLink href={featuredURL}>
3535
<a className={linkClassName('featured')}>{t('nav.featured')}</a>
36-
</Link>
37-
<Link href={allURL}>
36+
</NoPrefetchLink>
37+
<NoPrefetchLink href={allURL}>
3838
<a className={linkClassName('all')}>{t('nav.all')}</a>
39-
</Link>
39+
</NoPrefetchLink>
4040
<span onClick={handleTagButton} className={linkClassName('label')}>
4141
{t('nav.tag')}
4242
</span>

src/components/navbar/RepoNavbar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import Link from 'next/link';
21
import { useRouter } from 'next/router';
32
import { AiOutlineArrowLeft } from 'react-icons/ai';
43

4+
import { NoPrefetchLink } from '@/components/links/CustomLink';
5+
56
interface Props {
67
avatar: string;
78
uid: string;
@@ -31,7 +32,7 @@ const RepoDetailNavbar = ({ avatar, uid, t }: Props) => {
3132
<div className='text-center font-bold dark:text-gray-300'>
3233
{t('nav.title')}
3334
</div>
34-
<Link href={`/user/${uid}`}>
35+
<NoPrefetchLink href={`/user/${uid}`}>
3536
<div className='flex cursor-pointer items-center justify-end text-xs text-gray-500 hover:text-blue-400 dark:text-gray-400'>
3637
{t('nav.desc')}
3738
<a className='m-1 flex items-center'>
@@ -45,7 +46,7 @@ const RepoDetailNavbar = ({ avatar, uid, t }: Props) => {
4546
</a>
4647
{t('nav.desc2')}
4748
</div>
48-
</Link>
49+
</NoPrefetchLink>
4950
</div>
5051
</div>
5152
);

0 commit comments

Comments
 (0)