mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Added deprecation message when adding an extra anchor in behalf of the user. (#797)
This commit is contained in:
parent
7cc554c67a
commit
70b92e6b65
|
@ -1,6 +1,7 @@
|
||||||
import { resolve } from 'url'
|
import { resolve } from 'url'
|
||||||
import React, { Component, Children, PropTypes } from 'react'
|
import React, { Component, Children, PropTypes } from 'react'
|
||||||
import Router from './router'
|
import Router from './router'
|
||||||
|
import { warn, execOnce } from './utils'
|
||||||
|
|
||||||
export default class Link extends Component {
|
export default class Link extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
|
@ -69,6 +70,7 @@ export default class Link extends Component {
|
||||||
if (isAnchor) {
|
if (isAnchor) {
|
||||||
return React.cloneElement(child, props)
|
return React.cloneElement(child, props)
|
||||||
} else {
|
} else {
|
||||||
|
warnLink(`Warning: Every Link must be the parent of an anchor, this pattern is deprecated. Please add an anchor inside the <Link>.`)
|
||||||
return <a {...props}>{child}</a>
|
return <a {...props}>{child}</a>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -82,3 +84,5 @@ export function isLocal (href) {
|
||||||
return !/^(https?:)?\/\//.test(href) ||
|
return !/^(https?:)?\/\//.test(href) ||
|
||||||
origin === href.substr(0, origin.length)
|
origin === href.substr(0, origin.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const warnLink = execOnce(warn)
|
||||||
|
|
10
lib/utils.js
10
lib/utils.js
|
@ -4,6 +4,16 @@ export function warn (message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function execOnce (fn) {
|
||||||
|
let used = false
|
||||||
|
return (...args) => {
|
||||||
|
if (!used) {
|
||||||
|
used = true
|
||||||
|
fn.apply(this, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function deprecated (fn, message) {
|
export function deprecated (fn, message) {
|
||||||
if (process.env.NODE_ENV === 'production') return fn
|
if (process.env.NODE_ENV === 'production') return fn
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue