Commit 70b92e6b authored by Dan Zajdband's avatar Dan Zajdband Committed by Tim Neutkens

Added deprecation message when adding an extra anchor in behalf of the user. (#797)

parent 7cc554c6
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 { ...@@ -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) { ...@@ -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)
...@@ -4,6 +4,16 @@ export function warn (message) { ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment