Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put location on partialNextState #3569

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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