-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(antdsite): add a switch for prefetching.
- Loading branch information
1 parent
4bae484
commit c5dd49f
Showing
14 changed files
with
89 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/antdsite/src/default-theme/components/MyLink/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { Link } from 'gatsby'; | ||
import { Link as RouterLink } from '@reach/router'; | ||
import { PageContext } from 'antdsite/src/templates/PageContext'; | ||
import { resolvePathWithBase } from '../utils'; | ||
|
||
const MyLink: React.SFC<any> = ({ | ||
children, | ||
to, | ||
prefetch, | ||
...rest | ||
}: { | ||
children: React.ReactNode; | ||
to: string; | ||
prefetch: boolean; | ||
}) => { | ||
return ( | ||
<PageContext.Consumer> | ||
{({ webConfig: { base, prefetch: globalPrefetch } }) => { | ||
if (!prefetch || !globalPrefetch) { | ||
return ( | ||
<RouterLink to={resolvePathWithBase(to, base)} {...rest}> | ||
{children} | ||
</RouterLink> | ||
); | ||
} | ||
return ( | ||
<Link to={to} {...rest}> | ||
{children} | ||
</Link> | ||
); | ||
}} | ||
</PageContext.Consumer> | ||
); | ||
}; | ||
|
||
MyLink.defaultProps = { | ||
prefetch: true | ||
}; | ||
|
||
export default MyLink; |
11 changes: 3 additions & 8 deletions
11
packages/antdsite/src/default-theme/components/content/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
import React from 'react'; | ||
import Article from './Article'; | ||
import { PageContext } from 'antdsite'; | ||
|
||
export default class Content extends React.PureComponent { | ||
static contextType = PageContext; | ||
|
||
render() { | ||
return ( | ||
<> | ||
<div className="main-container"> | ||
<Article /> | ||
</div> | ||
</> | ||
<div className="main-container"> | ||
<Article /> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters