File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { resolve } from 'url'
22import React , { Component , Children , PropTypes } from 'react'
33import Router from './router'
4+ import { warn , execOnce } from './utils'
45
56export 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 ! / ^ ( h t t p s ? : ) ? \/ \/ / . test ( href ) ||
8385 origin === href . substr ( 0 , origin . length )
8486}
87+
88+ const warnLink = execOnce ( warn )
Original file line number Diff line number Diff 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+
717export function deprecated ( fn , message ) {
818 if ( process . env . NODE_ENV === 'production' ) return fn
919
You can’t perform that action at this time.
0 commit comments