Skip to content

Commit

Permalink
Remove default hashHistory and v2 compat flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
timdorr committed Apr 18, 2016
1 parent 26a3a03 commit 4d43bf4
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 707 deletions.
42 changes: 5 additions & 37 deletions modules/Router.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import createHashHistory from 'history/lib/createHashHistory'
import useQueries from 'history/lib/useQueries'
import React from 'react'

import createTransitionManager from './createTransitionManager'
import { routes } from './PropTypes'
import RouterContext from './RouterContext'
import { createRoutes } from './RouteUtils'
import { createRouterObject, createRoutingHistory } from './RouterUtils'
import { createRouterObject } from './RouterUtils'
import warning from './routerWarning'

function isDeprecatedHistory(history) {
return !history || !history.__v2_compatible__
}

const { func, object } = React.PropTypes

/**
Expand Down Expand Up @@ -62,12 +56,6 @@ const Router = React.createClass({
},

componentWillMount() {
const { parseQueryString, stringifyQuery } = this.props
warning(
!(parseQueryString || stringifyQuery),
'`parseQueryString` and `stringifyQuery` are deprecated. Please create a custom history. http://tiny.cc/router-customquerystring'
)

const { history, transitionManager, router } = this.createRouterObjects()

this._unlisten = transitionManager.listen((error, state) => {
Expand All @@ -91,34 +79,14 @@ const Router = React.createClass({
let { history } = this.props
const { routes, children } = this.props

if (isDeprecatedHistory(history)) {
history = this.wrapDeprecatedHistory(history)
}

const transitionManager = createTransitionManager(
history, createRoutes(routes || children)
history,
createRoutes(routes || children)
)
const router = createRouterObject(history, transitionManager)
const routingHistory = createRoutingHistory(history, transitionManager)

return { history: routingHistory, transitionManager, router }
},

wrapDeprecatedHistory(history) {
const { parseQueryString, stringifyQuery } = this.props

let createHistory
if (history) {
warning(false, 'It appears you have provided a deprecated history object to `<Router/>`, please use a history provided by ' +
'React Router with `import { browserHistory } from \'react-router\'` or `import { hashHistory } from \'react-router\'`. ' +
'If you are using a custom history please create it with `useRouterHistory`, see http://tiny.cc/router-usinghistory for details.')
createHistory = () => history
} else {
warning(false, '`Router` no longer defaults the history prop to hash history. Please use the `hashHistory` singleton instead. http://tiny.cc/router-defaulthistory')
createHistory = createHashHistory
}
history = { ...history, ...transitionManager }

return useQueries(createHistory)({ parseQueryString, stringifyQuery })
return { history, transitionManager, router }
},

/* istanbul ignore next: sanity check */
Expand Down
19 changes: 0 additions & 19 deletions modules/RouterUtils.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import deprecateObjectProperties from './deprecateObjectProperties'

export function createRouterObject(history, transitionManager) {
return {
...history,
setRouteLeaveHook: transitionManager.listenBeforeLeavingRoute,
isActive: transitionManager.isActive
}
}

// deprecated
export function createRoutingHistory(history, transitionManager) {
history = {
...history,
...transitionManager
}

if (__DEV__) {
history = deprecateObjectProperties(
history,
'`props.history` and `context.history` are deprecated. Please use `context.router`. http://tiny.cc/router-contextchanges'
)
}

return history
}
85 changes: 4 additions & 81 deletions modules/__tests__/_bc-Link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { Simulate } from 'react-addons-test-utils'
import { render } from 'react-dom'
import execSteps from './execSteps'
import createHistory from 'history/lib/createMemoryHistory'
import useRouterHistory from '../useRouterHistory'
import Router from '../Router'
import Route from '../Route'
import Link from '../Link'
import shouldWarn from './shouldWarn'

const createRouterHistory = useRouterHistory(createHistory)
const { click } = Simulate

describe('v1 Link', function () {
Expand Down Expand Up @@ -36,7 +38,7 @@ describe('v1 Link', function () {
}

render((
<Router history={createHistory('/')}>
<Router history={createRouterHistory('/')}>
<Route path="/" component={LinkWrapper} />
</Router>
), node, function () {
Expand All @@ -45,85 +47,6 @@ describe('v1 Link', function () {
})
})

describe('with params', function () {
class App extends Component {
render() {
return (
<div>
<Link
to="/hello/michael"
activeClassName="active"
>
Michael
</Link>
<Link
to="hello/ryan" query={{ the: 'query' }}
activeClassName="active"
>
Ryan
</Link>
</div>
)
}
}

it('is active when its params match', function (done) {
render((
<Router history={createHistory('/hello/michael')}>
<Route path="/" component={App}>
<Route path="hello/:name" component={Hello} />
</Route>
</Router>
), node, function () {
const a = node.querySelectorAll('a')[0]
expect(a.className.trim()).toEqual('active')
done()
})
})

it('is not active when its params do not match', function (done) {
render((
<Router history={createHistory('/hello/michael')}>
<Route path="/" component={App}>
<Route path="hello/:name" component={Hello} />
</Route>
</Router>
), node, function () {
const a = node.querySelectorAll('a')[1]
expect(a.className.trim()).toEqual('')
done()
})
})

it('is active when its params and query match', function (done) {
render((
<Router history={createHistory('/hello/ryan?the=query')}>
<Route path="/" component={App}>
<Route path="hello/:name" component={Hello} />
</Route>
</Router>
), node, function () {
const a = node.querySelectorAll('a')[1]
expect(a.className.trim()).toEqual('active')
done()
})
})

it('is not active when its query does not match', function (done) {
render((
<Router history={createHistory('/hello/ryan?the=other+query')}>
<Route path="/" component={App}>
<Route path="hello/:name" component={Hello} />
</Route>
</Router>
), node, function () {
const a = node.querySelectorAll('a')[1]
expect(a.className.trim()).toEqual('')
done()
})
})
})

it('transitions to the correct route with deprecated props', function (done) {
class LinkWrapper extends Component {
handleClick() {
Expand All @@ -134,7 +57,7 @@ describe('v1 Link', function () {
}
}

const history = createHistory('/')
const history = createRouterHistory('/')
const spy = spyOn(history, 'push').andCallThrough()

const steps = [
Expand Down
Loading

0 comments on commit 4d43bf4

Please sign in to comment.