Skip to content

Commit

Permalink
Put location on partialNextState (#3569)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion authored and timdorr committed Jun 23, 2016
1 parent 1cd4867 commit a4fee0f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
35 changes: 24 additions & 11 deletions modules/__tests__/matchRoutes-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import expect from 'expect'
import React from 'react'
import { createMemoryHistory } from 'history'
import { createRoutes } from '../RouteUtils'
import React from 'react'
import { canUseMembrane } from '../deprecateObjectProperties'
import IndexRoute from '../IndexRoute'
import matchRoutes from '../matchRoutes'
import Route from '../Route'
import IndexRoute from '../IndexRoute'
import { createRoutes } from '../RouteUtils'
import shouldWarn from './shouldWarn'

describe('matchRoutes', function () {
Expand Down Expand Up @@ -330,10 +331,16 @@ describe('matchRoutes', function () {
])
expect(match.params).toEqual({ groupId: 'foo', userId: '5' })

expect(getChildRoutes.calls[0].arguments[0].params).toEqual({
groupId: 'foo'
})
expect(getIndexRoute).toNotHaveBeenCalled()
const partialNextState = getChildRoutes.calls[0].arguments[0]
expect(partialNextState.params).toEqual({ groupId: 'foo' })
expect(partialNextState.location.pathname).toEqual('/foo/users/5')

// Only the calls below this point should emit deprecation warnings.
if (canUseMembrane) {
shouldWarn('deprecated')
}

expect(partialNextState.pathname).toEqual('/foo/users/5')

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

expect(getIndexRoute.calls[0].arguments[0].params).toEqual({
groupId: 'bar'
})
expect(getChildRoutes).toNotHaveBeenCalled()
const partialNextState = getIndexRoute.calls[0].arguments[0]
expect(partialNextState.params).toEqual({ groupId: 'bar' })
expect(partialNextState.location.pathname).toEqual('/bar/users')

// Only the calls below this point should emit deprecation warnings.
if (canUseMembrane) {
shouldWarn('deprecated')
}

expect(partialNextState.pathname).toEqual('/bar/users')

done()
}
Expand Down
12 changes: 10 additions & 2 deletions modules/matchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ function getChildRoutes(route, location, paramNames, paramValues, callback) {

let sync = true, result

const partialNextState = { params: createParams(paramNames, paramValues) }
const partialNextState = {
location,
params: createParams(paramNames, paramValues)
}

const partialNextStateWithLocation = makeStateWithLocation(
partialNextState, location
)
Expand All @@ -40,7 +44,11 @@ function getIndexRoute(route, location, paramNames, paramValues, callback) {
if (route.indexRoute) {
callback(null, route.indexRoute)
} else if (route.getIndexRoute) {
const partialNextState = { params: createParams(paramNames, paramValues) }
const partialNextState = {
location,
params: createParams(paramNames, paramValues)
}

const partialNextStateWithLocation = makeStateWithLocation(
partialNextState, location
)
Expand Down

0 comments on commit a4fee0f

Please sign in to comment.