Skip to content

Commit 612ff86

Browse files
committed
Throw instead of silently failing with history v3
1 parent 4e24ae7 commit 612ff86

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

modules/Router.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import createHashHistory from 'history/lib/createHashHistory'
22
import useQueries from 'history/lib/useQueries'
3+
import invariant from 'invariant'
34
import React from 'react'
45

56
import createTransitionManager from './createTransitionManager'
@@ -13,6 +14,12 @@ function isDeprecatedHistory(history) {
1314
return !history || !history.__v2_compatible__
1415
}
1516

17+
/* istanbul ignore next: sanity check */
18+
function isUnsupportedHistory(history) {
19+
// v3 histories expose getCurrentLocation, but aren't currently supported.
20+
return history && history.getCurrentLocation
21+
}
22+
1623
const { func, object } = React.PropTypes
1724

1825
/**
@@ -91,6 +98,13 @@ const Router = React.createClass({
9198
let { history } = this.props
9299
const { routes, children } = this.props
93100

101+
invariant(
102+
!isUnsupportedHistory(history),
103+
'You have provided a history object from created with history v3.x. ' +
104+
'This version of React Router is not compatible with v3 history ' +
105+
'objects. Please use history v2.x instead.'
106+
)
107+
94108
if (isDeprecatedHistory(history)) {
95109
history = this.wrapDeprecatedHistory(history)
96110
}

0 commit comments

Comments
 (0)