-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Changelog - Remove `getInitialProps` - Explain variants - Reflect latest changes in the prefetch api - Update UI
- Loading branch information
Showing
7 changed files
with
53 additions
and
53 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
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,39 +1,47 @@ | ||
import Router from 'next/router' | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default () => ( | ||
<div> | ||
{/* Prefetch using the declarative API */} | ||
<Link prefetch href='/'> | ||
<a>Home</a> | ||
</Link> | ||
|
||
<Link prefetch href='/features'> | ||
<a>Features</a> | ||
</Link> | ||
|
||
{/* we imperatively prefetch on hover */} | ||
<Link href='/about'> | ||
<a | ||
onMouseEnter={() => { | ||
Router.prefetch('/about') | ||
console.log('prefetching /about!') | ||
}} | ||
> | ||
About | ||
</a> | ||
</Link> | ||
|
||
<Link href='/contact'> | ||
<a> | ||
Contact (<small>NO-PREFETCHING</small>) | ||
</a> | ||
</Link> | ||
|
||
<style jsx>{` | ||
a { | ||
margin-right: 10px; | ||
} | ||
`}</style> | ||
</div> | ||
) | ||
export default function Header () { | ||
const router = useRouter() | ||
return ( | ||
<div className='root'> | ||
<h2>Default</h2> | ||
<p> | ||
Automatically prefetch pages in the background as soon the Link appears | ||
in the view: | ||
</p> | ||
<Link href='/'> | ||
<a>Home</a> | ||
</Link>{' '} | ||
<Link href='/features'> | ||
<a>Features</a> | ||
</Link> | ||
<h2>Imperative</h2> | ||
<p>Prefetch on onMouseEnter or on other events:</p> | ||
<Link prefetch={false} href='/about'> | ||
<a | ||
onMouseEnter={() => { | ||
router.prefetch('/about') | ||
console.log('prefetching /about!') | ||
}} | ||
> | ||
About | ||
</a> | ||
</Link> | ||
<h2>Disable</h2> | ||
<p>Disable prefetching</p> | ||
<Link prefetch={false} href='/contact'> | ||
<a>Contact</a> | ||
</Link> | ||
<style jsx>{` | ||
.root { | ||
border-bottom: 1px solid grey; | ||
padding-bottom: 8px; | ||
} | ||
a { | ||
margin-right: 10px; | ||
} | ||
`}</style> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default () => <p>This is the ABOUT page.</p> | ||
export default () => <h1>This is the ABOUT page.</h1> |
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 +1 @@ | ||
export default () => <p>This is the CONTACT page.</p> | ||
export default () => <h1>This is the CONTACT page.</h1> |
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 +1 @@ | ||
export default () => <p>This is the FEATURES page.</p> | ||
export default () => <h1>This is the FEATURES page.</h1> |
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 +1 @@ | ||
export default () => <p>This is the HOME page</p> | ||
export default () => <h1>This is the HOME page</h1> |