Skip to content

Commit a4fee0f

Browse files
taiontimdorr
authored andcommitted
Put location on partialNextState (#3569)
1 parent 1cd4867 commit a4fee0f

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

modules/__tests__/matchRoutes-test.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import expect from 'expect'
2-
import React from 'react'
32
import { createMemoryHistory } from 'history'
4-
import { createRoutes } from '../RouteUtils'
3+
import React from 'react'
4+
import { canUseMembrane } from '../deprecateObjectProperties'
5+
import IndexRoute from '../IndexRoute'
56
import matchRoutes from '../matchRoutes'
67
import Route from '../Route'
7-
import IndexRoute from '../IndexRoute'
8+
import { createRoutes } from '../RouteUtils'
89
import shouldWarn from './shouldWarn'
910

1011
describe('matchRoutes', function () {
@@ -330,10 +331,16 @@ describe('matchRoutes', function () {
330331
])
331332
expect(match.params).toEqual({ groupId: 'foo', userId: '5' })
332333

333-
expect(getChildRoutes.calls[0].arguments[0].params).toEqual({
334-
groupId: 'foo'
335-
})
336-
expect(getIndexRoute).toNotHaveBeenCalled()
334+
const partialNextState = getChildRoutes.calls[0].arguments[0]
335+
expect(partialNextState.params).toEqual({ groupId: 'foo' })
336+
expect(partialNextState.location.pathname).toEqual('/foo/users/5')
337+
338+
// Only the calls below this point should emit deprecation warnings.
339+
if (canUseMembrane) {
340+
shouldWarn('deprecated')
341+
}
342+
343+
expect(partialNextState.pathname).toEqual('/foo/users/5')
337344

338345
done()
339346
}
@@ -347,10 +354,16 @@ describe('matchRoutes', function () {
347354
expect(match).toExist()
348355
expect(match.routes.map(r => r.name)).toEqual([ 'users', 'jsx' ])
349356

350-
expect(getIndexRoute.calls[0].arguments[0].params).toEqual({
351-
groupId: 'bar'
352-
})
353-
expect(getChildRoutes).toNotHaveBeenCalled()
357+
const partialNextState = getIndexRoute.calls[0].arguments[0]
358+
expect(partialNextState.params).toEqual({ groupId: 'bar' })
359+
expect(partialNextState.location.pathname).toEqual('/bar/users')
360+
361+
// Only the calls below this point should emit deprecation warnings.
362+
if (canUseMembrane) {
363+
shouldWarn('deprecated')
364+
}
365+
366+
expect(partialNextState.pathname).toEqual('/bar/users')
354367

355368
done()
356369
}

modules/matchRoutes.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ function getChildRoutes(route, location, paramNames, paramValues, callback) {
1414

1515
let sync = true, result
1616

17-
const partialNextState = { params: createParams(paramNames, paramValues) }
17+
const partialNextState = {
18+
location,
19+
params: createParams(paramNames, paramValues)
20+
}
21+
1822
const partialNextStateWithLocation = makeStateWithLocation(
1923
partialNextState, location
2024
)
@@ -40,7 +44,11 @@ function getIndexRoute(route, location, paramNames, paramValues, callback) {
4044
if (route.indexRoute) {
4145
callback(null, route.indexRoute)
4246
} else if (route.getIndexRoute) {
43-
const partialNextState = { params: createParams(paramNames, paramValues) }
47+
const partialNextState = {
48+
location,
49+
params: createParams(paramNames, paramValues)
50+
}
51+
4452
const partialNextStateWithLocation = makeStateWithLocation(
4553
partialNextState, location
4654
)

0 commit comments

Comments
 (0)