Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw instead of silently failing with history v3 #3571

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/Router.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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

/**
Expand Down Expand Up @@ -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. ' +
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"from created with", is that a typo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

):

'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)
}
Expand Down