From 847954598cec24803065a11cf5e63c040e37710c Mon Sep 17 00:00:00 2001 From: TrexinanF14 Date: Thu, 23 Jun 2016 09:07:51 -0400 Subject: [PATCH 1/4] Add warning to link.js --- modules/Link.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/Link.js b/modules/Link.js index 98c0cbd452..0019597ebf 100644 --- a/modules/Link.js +++ b/modules/Link.js @@ -98,7 +98,9 @@ const Link = React.createClass({ if (allowTransition) { const { to, query, hash, state } = this.props const location = createLocationDescriptor(to, { query, hash, state }) - + + warning(this.context.router != undefined, "No router context, are you sure your link is inside a valid Router component?"); + this.context.router.push(location) } }, From 8ceadf5a3a212898e79498b63e3ee961108668c1 Mon Sep 17 00:00:00 2001 From: TrexinanF14 Date: Thu, 23 Jun 2016 09:15:01 -0400 Subject: [PATCH 2/4] Formatting changes. --- modules/Link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Link.js b/modules/Link.js index 0019597ebf..90463f18a2 100644 --- a/modules/Link.js +++ b/modules/Link.js @@ -99,7 +99,7 @@ const Link = React.createClass({ const { to, query, hash, state } = this.props const location = createLocationDescriptor(to, { query, hash, state }) - warning(this.context.router != undefined, "No router context, are you sure your link is inside a valid Router component?"); + warning(this.context.router != undefined, 'No router context, are you sure your link is inside a valid Router component?') this.context.router.push(location) } From 4f0376ca0d6228758615de09c9c4461690712040 Mon Sep 17 00:00:00 2001 From: TrexinanF14 Date: Thu, 23 Jun 2016 10:56:16 -0400 Subject: [PATCH 3/4] Move warning in link.js, make invariant. --- modules/Link.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/Link.js b/modules/Link.js index 90463f18a2..4852ff99fd 100644 --- a/modules/Link.js +++ b/modules/Link.js @@ -1,5 +1,6 @@ import React from 'react' import warning from './routerWarning' +import invariant from 'invariant' import { routerShape } from './PropTypes' const { bool, object, string, func, oneOfType } = React.PropTypes @@ -73,6 +74,11 @@ const Link = React.createClass({ }, handleClick(event) { + invariant( + this.context.router, + 's rendered outside of a router context cannot handle clicks.' + ) + let allowTransition = true if (this.props.onClick) @@ -99,8 +105,6 @@ const Link = React.createClass({ const { to, query, hash, state } = this.props const location = createLocationDescriptor(to, { query, hash, state }) - warning(this.context.router != undefined, 'No router context, are you sure your link is inside a valid Router component?') - this.context.router.push(location) } }, From 37ba905ab50778db561e70e8d243b5db3ea5790b Mon Sep 17 00:00:00 2001 From: TrexinanF14 Date: Thu, 23 Jun 2016 11:31:29 -0400 Subject: [PATCH 4/4] Update link.js, nit. --- modules/Link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Link.js b/modules/Link.js index 4852ff99fd..08c4aba517 100644 --- a/modules/Link.js +++ b/modules/Link.js @@ -104,7 +104,7 @@ const Link = React.createClass({ if (allowTransition) { const { to, query, hash, state } = this.props const location = createLocationDescriptor(to, { query, hash, state }) - + this.context.router.push(location) } },