From 612ff86909df47711b221dcaa0e306961dd33056 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Wed, 22 Jun 2016 22:51:02 -0400 Subject: [PATCH] Throw instead of silently failing with history v3 --- modules/Router.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/Router.js b/modules/Router.js index 5444674329..d2d3f8cc37 100644 --- a/modules/Router.js +++ b/modules/Router.js @@ -1,5 +1,6 @@ import createHashHistory from 'history/lib/createHashHistory' import useQueries from 'history/lib/useQueries' +import invariant from 'invariant' import React from 'react' import createTransitionManager from './createTransitionManager' @@ -13,6 +14,12 @@ function isDeprecatedHistory(history) { return !history || !history.__v2_compatible__ } +/* istanbul ignore next: sanity check */ +function isUnsupportedHistory(history) { + // v3 histories expose getCurrentLocation, but aren't currently supported. + return history && history.getCurrentLocation +} + const { func, object } = React.PropTypes /** @@ -91,6 +98,13 @@ const Router = React.createClass({ let { history } = this.props const { routes, children } = this.props + invariant( + !isUnsupportedHistory(history), + 'You have provided a history object from created with history v3.x. ' + + 'This version of React Router is not compatible with v3 history ' + + 'objects. Please use history v2.x instead.' + ) + if (isDeprecatedHistory(history)) { history = this.wrapDeprecatedHistory(history) }