Skip to content

Commit 842c909

Browse files
committed
Fix this in getComponent and getComponents (#3306)
1 parent 98b8d12 commit 842c909

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [HEAD]
2+
> Unreleased
3+
4+
- **Bugfix:** Fix `this` in `getComponent` and `getComponents` ([#3306])
5+
6+
[HEAD]: https://github.com/reactjs/react-router/compare/latest...HEAD
7+
[#3306]: https://github.com/reactjs/react-router/pull/3306
8+
9+
110
## [v2.2.0]
211
> April 13, 2016
312

modules/__tests__/Router-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,11 @@ describe('Router', function () {
331331

332332
it('should support getComponent', function (done) {
333333
const Component = () => <div />
334-
const getComponent = (nextState, callback) => {
334+
335+
function getComponent(nextState, callback) {
336+
expect(this.getComponent).toBe(getComponent)
335337
expect(nextState.location.pathname).toBe('/')
338+
336339
setTimeout(() => callback(null, Component))
337340
}
338341

@@ -352,8 +355,10 @@ describe('Router', function () {
352355
const foo = () => <div />
353356
const bar = () => <div />
354357

355-
const getComponents = (nextState, callback) => {
358+
function getComponents(nextState, callback) {
359+
expect(this.getComponents).toBe(getComponents)
356360
expect(nextState.location.pathname).toBe('/')
361+
357362
setTimeout(() => callback(null, { foo, bar }))
358363
}
359364

modules/getComponents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function getComponentsForRoute(nextState, route, callback) {
3333
Object.assign(nextStateWithLocation, location)
3434
}
3535

36-
getComponent(nextStateWithLocation, callback)
36+
getComponent.call(route, nextStateWithLocation, callback)
3737
return
3838
}
3939

0 commit comments

Comments
 (0)