Skip to content

Commit da81910

Browse files
committed
Merge pull request #3340 from reactjs/remove-context-history-location
[3.0] Remove deprecations.
2 parents b3c37a8 + 1a5666e commit da81910

23 files changed

+41
-1575
lines changed

modules/History.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

modules/Lifecycle.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

modules/Link.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import warning from './routerWarning'
32
import { routerShape } from './PropTypes'
43

54
const { bool, object, string, func, oneOfType } = React.PropTypes
@@ -21,14 +20,6 @@ function isEmptyObject(object) {
2120
return true
2221
}
2322

24-
function createLocationDescriptor(to, { query, hash, state }) {
25-
if (query || hash || state) {
26-
return { pathname: to, query, hash, state }
27-
}
28-
29-
return to
30-
}
31-
3223
/**
3324
* A <Link> is used to create an <a> element that links to a route.
3425
* When that route is active, the link gets the value of its
@@ -95,29 +86,22 @@ const Link = React.createClass({
9586
event.preventDefault()
9687

9788
if (allowTransition) {
98-
const { to, query, hash, state } = this.props
99-
const location = createLocationDescriptor(to, { query, hash, state })
89+
const { to } = this.props
10090

101-
this.context.router.push(location)
91+
this.context.router.push(to)
10292
}
10393
},
10494

10595
render() {
106-
const { to, query, hash, state, activeClassName, activeStyle, onlyActiveOnIndex, ...props } = this.props
107-
warning(
108-
!(query || hash || state),
109-
'the `query`, `hash`, and `state` props on `<Link>` are deprecated, use `<Link to={{ pathname, query, hash, state }}/>. http://tiny.cc/router-isActivedeprecated'
110-
)
111-
96+
const { to, activeClassName, activeStyle, onlyActiveOnIndex, ...props } = this.props
11297
// Ignore if rendered outside the context of router, simplifies unit testing.
11398
const { router } = this.context
11499

115100
if (router) {
116-
const location = createLocationDescriptor(to, { query, hash, state })
117-
props.href = router.createHref(location)
101+
props.href = router.createHref(to)
118102

119103
if (activeClassName || (activeStyle != null && !isEmptyObject(activeStyle))) {
120-
if (router.isActive(location, onlyActiveOnIndex)) {
104+
if (router.isActive(to, onlyActiveOnIndex)) {
121105
if (activeClassName) {
122106
if (props.className) {
123107
props.className += ` ${activeClassName}`

modules/RouteContext.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

modules/Router.js

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import createHashHistory from 'history/lib/createHashHistory'
2-
import useQueries from 'history/lib/useQueries'
31
import React from 'react'
42

53
import createTransitionManager from './createTransitionManager'
64
import { routes } from './InternalPropTypes'
75
import RouterContext from './RouterContext'
86
import { createRoutes } from './RouteUtils'
9-
import { createRouterObject, createRoutingHistory } from './RouterUtils'
7+
import { createRouterObject } from './RouterUtils'
108
import warning from './routerWarning'
119

12-
function isDeprecatedHistory(history) {
13-
return !history || !history.__v2_compatible__
14-
}
15-
1610
const { func, object } = React.PropTypes
1711

1812
/**
@@ -62,13 +56,7 @@ const Router = React.createClass({
6256
},
6357

6458
componentWillMount() {
65-
const { parseQueryString, stringifyQuery } = this.props
66-
warning(
67-
!(parseQueryString || stringifyQuery),
68-
'`parseQueryString` and `stringifyQuery` are deprecated. Please create a custom history. http://tiny.cc/router-customquerystring'
69-
)
70-
71-
const { history, transitionManager, router } = this.createRouterObjects()
59+
const { transitionManager, router } = this.createRouterObjects()
7260

7361
this._unlisten = transitionManager.listen((error, state) => {
7462
if (error) {
@@ -78,7 +66,6 @@ const Router = React.createClass({
7866
}
7967
})
8068

81-
this.history = history
8269
this.router = router
8370
},
8471

@@ -91,34 +78,13 @@ const Router = React.createClass({
9178
let { history } = this.props
9279
const { routes, children } = this.props
9380

94-
if (isDeprecatedHistory(history)) {
95-
history = this.wrapDeprecatedHistory(history)
96-
}
97-
9881
const transitionManager = createTransitionManager(
99-
history, createRoutes(routes || children)
82+
history,
83+
createRoutes(routes || children)
10084
)
10185
const router = createRouterObject(history, transitionManager)
102-
const routingHistory = createRoutingHistory(history, transitionManager)
103-
104-
return { history: routingHistory, transitionManager, router }
105-
},
106-
107-
wrapDeprecatedHistory(history) {
108-
const { parseQueryString, stringifyQuery } = this.props
109-
110-
let createHistory
111-
if (history) {
112-
warning(false, 'It appears you have provided a deprecated history object to `<Router/>`, please use a history provided by ' +
113-
'React Router with `import { browserHistory } from \'react-router\'` or `import { hashHistory } from \'react-router\'`. ' +
114-
'If you are using a custom history please create it with `useRouterHistory`, see http://tiny.cc/router-usinghistory for details.')
115-
createHistory = () => history
116-
} else {
117-
warning(false, '`Router` no longer defaults the history prop to hash history. Please use the `hashHistory` singleton instead. http://tiny.cc/router-defaulthistory')
118-
createHistory = createHashHistory
119-
}
12086

121-
return useQueries(createHistory)({ parseQueryString, stringifyQuery })
87+
return { transitionManager, router }
12288
},
12389

12490
/* istanbul ignore next: sanity check */
@@ -153,7 +119,6 @@ const Router = React.createClass({
153119

154120
return render({
155121
...props,
156-
history: this.history,
157122
router: this.router,
158123
location,
159124
routes,

modules/RouterContext.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import invariant from 'invariant'
22
import React from 'react'
33

4-
import deprecateObjectProperties from './deprecateObjectProperties'
54
import getRouteParams from './getRouteParams'
65
import { isReactChildren } from './RouteUtils'
7-
import warning from './routerWarning'
86

97
const { array, func, object } = React.PropTypes
108

@@ -15,9 +13,7 @@ const { array, func, object } = React.PropTypes
1513
const RouterContext = React.createClass({
1614

1715
propTypes: {
18-
history: object,
1916
router: object.isRequired,
20-
location: object.isRequired,
2117
routes: array.isRequired,
2218
params: object.isRequired,
2319
components: array.isRequired,
@@ -31,36 +27,21 @@ const RouterContext = React.createClass({
3127
},
3228

3329
childContextTypes: {
34-
history: object,
35-
location: object.isRequired,
3630
router: object.isRequired
3731
},
3832

3933
getChildContext() {
40-
let { router, history, location } = this.props
41-
if (!router) {
42-
warning(false, '`<RouterContext>` expects a `router` rather than a `history`')
43-
44-
router = {
45-
...history,
46-
setRouteLeaveHook: history.listenBeforeLeavingRoute
47-
}
48-
delete router.listenBeforeLeavingRoute
49-
}
50-
51-
if (__DEV__) {
52-
location = deprecateObjectProperties(location, '`context.location` is deprecated, please use a route component\'s `props.location` instead. http://tiny.cc/router-accessinglocation')
34+
return {
35+
router: this.props.router
5336
}
54-
55-
return { history, location, router }
5637
},
5738

5839
createElement(component, props) {
5940
return component == null ? null : this.props.createElement(component, props)
6041
},
6142

6243
render() {
63-
const { history, location, routes, params, components } = this.props
44+
const { location, routes, params, components } = this.props
6445
let element = null
6546

6647
if (components) {
@@ -71,7 +52,6 @@ const RouterContext = React.createClass({
7152
const route = routes[index]
7253
const routeParams = getRouteParams(route, params)
7354
const props = {
74-
history,
7555
location,
7656
params,
7757
route,

modules/RouterUtils.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
1-
import deprecateObjectProperties from './deprecateObjectProperties'
2-
31
export function createRouterObject(history, transitionManager) {
42
return {
53
...history,
64
setRouteLeaveHook: transitionManager.listenBeforeLeavingRoute,
75
isActive: transitionManager.isActive
86
}
97
}
10-
11-
// deprecated
12-
export function createRoutingHistory(history, transitionManager) {
13-
history = {
14-
...history,
15-
...transitionManager
16-
}
17-
18-
if (__DEV__) {
19-
history = deprecateObjectProperties(
20-
history,
21-
'`props.history` and `context.history` are deprecated. Please use `context.router`. http://tiny.cc/router-contextchanges'
22-
)
23-
}
24-
25-
return history
26-
}

modules/TransitionUtils.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { loopAsync } from './AsyncUtils'
2-
import warning from './routerWarning'
32

43
function createTransitionHook(hook, route, asyncArity) {
54
return function (...args) {
@@ -38,21 +37,7 @@ function runTransitionHooks(length, iter, callback) {
3837
}
3938

4039
let redirectInfo
41-
function replace(location, deprecatedPathname, deprecatedQuery) {
42-
if (deprecatedPathname) {
43-
warning(
44-
false,
45-
'`replaceState(state, pathname, query) is deprecated; use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated'
46-
)
47-
redirectInfo = {
48-
pathname: deprecatedPathname,
49-
query: deprecatedQuery,
50-
state: location
51-
}
52-
53-
return
54-
}
55-
40+
function replace(location) {
5641
redirectInfo = location
5742
}
5843

0 commit comments

Comments
 (0)