Skip to content

Commit ebb8d20

Browse files
committed
[fixed] Remove direct calls to createLocation.
createLocation is now deprecated in history. This updates to the new instance method form provided by any history instance.
1 parent 356c521 commit ebb8d20

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

modules/__tests__/matchRoutes-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import Route from '../Route'
44

55
import assert from 'assert'
66
import expect from 'expect'
7-
import { createLocation } from 'history'
7+
import { createMemoryHistory } from 'history'
88
import { createRoutes } from '../RouteUtils'
99
import matchRoutes from '../matchRoutes'
1010

1111
describe('matchRoutes', function () {
1212

1313
let routes, RootRoute, UsersRoute, UsersIndexRoute, UserRoute, PostRoute, FilesRoute, AboutRoute, TeamRoute, ProfileRoute, CatchAllRoute
14+
let createLocation = createMemoryHistory().createLocation
1415
beforeEach(function () {
1516
/*
1617
<Route>

modules/__tests__/serverRendering-test.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*eslint react/prop-types: 0*/
33
import expect from 'expect'
44
import React from 'react'
5-
import createLocation from 'history/lib/createLocation'
5+
import createMemoryHistory from 'history/lib/createMemoryHistory'
66
import RoutingContext from '../RoutingContext'
77
import match from '../match'
88
import Link from '../Link'
@@ -71,8 +71,9 @@ describe('server rendering', function () {
7171
})
7272

7373
it('works', function (done) {
74-
const location = createLocation('/dashboard')
75-
match({ routes, location }, function (error, redirectLocation, renderProps) {
74+
const history = createMemoryHistory()
75+
const location = history.createLocation('/dashboard')
76+
match({ routes, history, location }, function (error, redirectLocation, renderProps) {
7677
const string = React.renderToString(
7778
<RoutingContext {...renderProps} />
7879
)
@@ -82,8 +83,9 @@ describe('server rendering', function () {
8283
})
8384

8485
it('renders active Links as active', function (done) {
85-
const location = createLocation('/about')
86-
match({ routes, location }, function (error, redirectLocation, renderProps) {
86+
const history = createMemoryHistory()
87+
const location = history.createLocation('/about')
88+
match({ routes, history, location }, function (error, redirectLocation, renderProps) {
8789
const string = React.renderToString(
8890
<RoutingContext {...renderProps} />
8991
)
@@ -94,8 +96,9 @@ describe('server rendering', function () {
9496
})
9597

9698
it('sends the redirect location', function (done) {
97-
const location = createLocation('/company')
98-
match({ routes, location }, function (error, redirectLocation) {
99+
const history = createMemoryHistory()
100+
const location = history.createLocation('/company')
101+
match({ routes, history, location }, function (error, redirectLocation) {
99102
expect(redirectLocation).toExist()
100103
expect(redirectLocation.pathname).toEqual('/about')
101104
expect(redirectLocation.search).toEqual('')
@@ -106,11 +109,12 @@ describe('server rendering', function () {
106109
})
107110

108111
it('sends null values when no routes match', function (done) {
109-
const location = createLocation('/no-match')
110-
match({ routes, location }, function (error, redirectLocation, state) {
111-
expect(error).toBe(null)
112-
expect(redirectLocation).toBe(null)
113-
expect(state).toBe(null)
112+
const history = createMemoryHistory()
113+
const location = history.createLocation('/no-match')
114+
match({ routes, history, location }, function (error, redirectLocation, state) {
115+
expect(error).toNotExist()
116+
expect(redirectLocation).toNotExist()
117+
expect(state).toNotExist()
114118
done()
115119
})
116120
})

modules/useRoutes.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import warning from 'warning'
22
import { REPLACE } from 'history/lib/Actions'
33
import useQueries from 'history/lib/useQueries'
4-
import createLocation from 'history/lib/createLocation'
54
import computeChangedRoutes from './computeChangedRoutes'
65
import { runEnterHooks, runLeaveHooks } from './TransitionUtils'
76
import { default as _isActive } from './isActive'
@@ -55,7 +54,7 @@ function useRoutes(createHistory) {
5554
}
5655

5756
function createLocationFromRedirectInfo({ pathname, query, state }) {
58-
return createLocation(
57+
return history.createLocation(
5958
history.createPath(pathname, query), state, REPLACE, history.createKey()
6059
)
6160
}
@@ -181,7 +180,7 @@ function useRoutes(createHistory) {
181180
} else if (hooks.indexOf(hook) === -1) {
182181
hooks.push(hook)
183182
}
184-
183+
185184
return function () {
186185
let hooks = RouteHooks[routeID]
187186

0 commit comments

Comments
 (0)