|
3 | 3 | import { resolve, format, parse } from 'url'
|
4 | 4 | import React, { Component, Children } from 'react'
|
5 | 5 | import PropTypes from 'prop-types'
|
6 |
| -import exact from 'prop-types-exact' |
7 | 6 | import Router, { _rewriteUrlForNextExport } from './router'
|
8 | 7 | import { warn, execOnce, getLocationOrigin } from './utils'
|
9 | 8 |
|
@@ -35,28 +34,6 @@ function memoizedFormatUrl (formatUrl) {
|
35 | 34 | }
|
36 | 35 |
|
37 | 36 | class Link extends Component {
|
38 |
| - static propTypes = exact({ |
39 |
| - href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired, |
40 |
| - as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), |
41 |
| - prefetch: PropTypes.bool, |
42 |
| - replace: PropTypes.bool, |
43 |
| - shallow: PropTypes.bool, |
44 |
| - passHref: PropTypes.bool, |
45 |
| - scroll: PropTypes.bool, |
46 |
| - children: PropTypes.oneOfType([ |
47 |
| - PropTypes.element, |
48 |
| - (props, propName) => { |
49 |
| - const value = props[propName] |
50 |
| - |
51 |
| - if (typeof value === 'string') { |
52 |
| - warnLink(`Warning: You're using a string directly inside <Link>. This usage has been deprecated. Please add an <a> tag as child of <Link>`) |
53 |
| - } |
54 |
| - |
55 |
| - return null |
56 |
| - } |
57 |
| - ]).isRequired |
58 |
| - }) |
59 |
| - |
60 | 37 | componentDidMount () {
|
61 | 38 | this.prefetch()
|
62 | 39 | }
|
@@ -177,4 +154,30 @@ class Link extends Component {
|
177 | 154 | }
|
178 | 155 | }
|
179 | 156 |
|
| 157 | +if (process.env.NODE_ENV === 'development') { |
| 158 | + // This module gets removed by webpack.IgnorePlugin |
| 159 | + const exact = require('prop-types-exact') |
| 160 | + Link.propTypes = exact({ |
| 161 | + href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired, |
| 162 | + as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), |
| 163 | + prefetch: PropTypes.bool, |
| 164 | + replace: PropTypes.bool, |
| 165 | + shallow: PropTypes.bool, |
| 166 | + passHref: PropTypes.bool, |
| 167 | + scroll: PropTypes.bool, |
| 168 | + children: PropTypes.oneOfType([ |
| 169 | + PropTypes.element, |
| 170 | + (props, propName) => { |
| 171 | + const value = props[propName] |
| 172 | + |
| 173 | + if (typeof value === 'string') { |
| 174 | + warnLink(`Warning: You're using a string directly inside <Link>. This usage has been deprecated. Please add an <a> tag as child of <Link>`) |
| 175 | + } |
| 176 | + |
| 177 | + return null |
| 178 | + } |
| 179 | + ]).isRequired |
| 180 | + }) |
| 181 | +} |
| 182 | + |
180 | 183 | export default Link
|
0 commit comments