Skip to content
Merged
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
50 changes: 26 additions & 24 deletions modules/getComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,37 @@ function getComponentsForRoute(nextState, route, callback) {
}

const getComponent = route.getComponent || route.getComponents
if (getComponent) {
let nextStateWithLocation = { ...nextState }
const { location } = nextState

if (__DEV__ && canUseMembrane) {
// I don't use deprecateObjectProperties here because I want to keep the
// same code path between development and production, in that we just
// assign extra properties to the copy of the state object in both cases.
for (const prop in location) {
if (!Object.prototype.hasOwnProperty.call(location, prop)) {
continue
}
if (!getComponent) {
callback()
return
}

const { location } = nextState
let nextStateWithLocation

if (__DEV__ && canUseMembrane) {
nextStateWithLocation = { ...nextState }

Object.defineProperty(nextStateWithLocation, prop, {
get() {
warning(false, 'Accessing location properties from the first argument to `getComponent` and `getComponents` is deprecated. That argument is now the router state (`nextState`) rather than the location. To access the location, use `nextState.location`.')
return location[prop]
}
})
// I don't use deprecateObjectProperties here because I want to keep the
// same code path between development and production, in that we just
// assign extra properties to the copy of the state object in both cases.
for (const prop in location) {
if (!Object.prototype.hasOwnProperty.call(location, prop)) {
continue
}
} else {
Object.assign(nextStateWithLocation, location)
}

getComponent.call(route, nextStateWithLocation, callback)
return
Object.defineProperty(nextStateWithLocation, prop, {
get() {
warning(false, 'Accessing location properties from the first argument to `getComponent` and `getComponents` is deprecated. That argument is now the router state (`nextState`) rather than the location. To access the location, use `nextState.location`.')
return location[prop]
}
})
}
} else {
nextStateWithLocation = { ...nextState, ...location }
}

callback()
getComponent.call(route, nextStateWithLocation, callback)
}

/**
Expand Down