1
0
Fork 0
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:
Dan Zajdband 2017-01-16 18:02:11 -03:00 committed by Tim Neutkens
parent 7cc554c67a
commit 70b92e6b65
2 changed files with 14 additions and 0 deletions

View file

@ -1,6 +1,7 @@
import { resolve } from 'url'
import React, { Component, Children, PropTypes } from 'react'
import Router from './router'
import { warn, execOnce } from './utils'
export default class Link extends Component {
constructor (props) {
@ -69,6 +70,7 @@ export default class Link extends Component {
if (isAnchor) {
return React.cloneElement(child, props)
} 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>
}
})
@ -82,3 +84,5 @@ export function isLocal (href) {
return !/^(https?:)?\/\//.test(href) ||
origin === href.substr(0, origin.length)
}
const warnLink = execOnce(warn)

View file

@ -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) {
if (process.env.NODE_ENV === 'production') return fn