Skip to content

Commit 70b92e6

Browse files
impronunciabletimneutkens
authored andcommitted
Added deprecation message when adding an extra anchor in behalf of the user. (vercel#797)
1 parent 7cc554c commit 70b92e6

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/link.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { resolve } from 'url'
22
import React, { Component, Children, PropTypes } from 'react'
33
import Router from './router'
4+
import { warn, execOnce } from './utils'
45

56
export default class Link extends Component {
67
constructor (props) {
@@ -69,6 +70,7 @@ export default class Link extends Component {
6970
if (isAnchor) {
7071
return React.cloneElement(child, props)
7172
} else {
73+
warnLink(`Warning: Every Link must be the parent of an anchor, this pattern is deprecated. Please add an anchor inside the <Link>.`)
7274
return <a {...props}>{child}</a>
7375
}
7476
})
@@ -82,3 +84,5 @@ export function isLocal (href) {
8284
return !/^(https?:)?\/\//.test(href) ||
8385
origin === href.substr(0, origin.length)
8486
}
87+
88+
const warnLink = execOnce(warn)

lib/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ export function warn (message) {
44
}
55
}
66

7+
export function execOnce (fn) {
8+
let used = false
9+
return (...args) => {
10+
if (!used) {
11+
used = true
12+
fn.apply(this, args)
13+
}
14+
}
15+
}
16+
717
export function deprecated (fn, message) {
818
if (process.env.NODE_ENV === 'production') return fn
919

0 commit comments

Comments
 (0)