2016-12-15 19:13:40 +00:00
|
|
|
import React from 'react'
|
2017-02-15 08:52:22 +00:00
|
|
|
import Link from './link'
|
|
|
|
import Router from './router'
|
|
|
|
import { warn, execOnce } from './utils'
|
|
|
|
|
|
|
|
const warnImperativePrefetch = execOnce(() => {
|
|
|
|
const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n' +
|
|
|
|
'> Use "Router.prefetch(href)" instead.'
|
|
|
|
warn(message)
|
|
|
|
})
|
|
|
|
|
|
|
|
const wantLinkPrefetch = execOnce(() => {
|
|
|
|
const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n' +
|
|
|
|
'> Use "<Link prefetch />" instead.'
|
|
|
|
warn(message)
|
|
|
|
})
|
|
|
|
|
|
|
|
export function prefetch (href) {
|
|
|
|
warnImperativePrefetch()
|
|
|
|
return Router.prefetch(href)
|
2017-01-02 11:18:14 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 19:13:40 +00:00
|
|
|
export default class LinkPrefetch extends React.Component {
|
|
|
|
render () {
|
2017-02-15 08:52:22 +00:00
|
|
|
wantLinkPrefetch()
|
|
|
|
const props = {
|
|
|
|
...this.props,
|
2017-02-15 14:01:03 +00:00
|
|
|
prefetch: this.props.prefetch !== false
|
2016-12-15 19:13:40 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 08:52:22 +00:00
|
|
|
return (<Link {...props} />)
|
2016-12-15 19:13:40 +00:00
|
|
|
}
|
|
|
|
}
|